#include <Arduino.h> #include <LED.h>

LED led;

// LED pins const int LED_DIGIT_PINS[] = {A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11};

// Voltage pins const int VOLTAGE_PIN = A13;

int led_state = 0;

void setup() { // Setup LED pins led.setup(LED_DIGIT_PINS);

// Setup voltage pin pinMode(VOLTAGE_PIN, INPUT); }

void loop() { // Read voltage int voltage = analogRead(VOLTAGE_PIN);

// Convert voltage to LED state int new_state = map(voltage, 0, 1024, 0, 12);

// Check if LED state has changed if (new_state != led_state) { // Set new LED state led.set(new_state);

// Store new LED state
led_state = new_state;

} }

Arduino Car Voltmeter: 12V/24V Digital LED Gauge - DIY Project

原文地址: https://www.cveoy.top/t/topic/llYn 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录