Lenguaje C++ — Arduino Uno simulation

Programación de encendido de leds por voltaje variable

An interactive Arduino Uno circuit simulation you can run free in your browser on Velxio, by albertoarangurenp.

Components

Sketch code

// Blink LED Example
// Toggles the built-in LED on pin 13

float V2;
int readVal;
int analogPin = A0;
int ledPinVerde = 10;
int LedPinAmarillo = 9;
int LedPinRojo = 11;

void setup() {
  pinMode(13, OUTPUT);
  Serial.begin(9600);
  pinMode(analogPin, INPUT);
  pinMode(ledPinVerde, OUTPUT);
  pinMode(LedPinAmarillo, OUTPUT);
  pinMode(LedPinRojo, OUTPUT);
  pinMode(ledPinVerde, LOW);
  pinMode(LedPinAmarillo, LOW);
  pinMode(LedPinRojo, LOW);
}

// < - > - <= - >= - == - != - && - ||
void loop() {
  digitalWrite(13, HIGH);
  delay(1000);
  digitalWrite(13, LOW);
  delay(1000);

  readVal = analogRead(analogPin);
  V2 = (5.*readVal)/1023.;
  // 0V = Todos los leds apagados. Si V = 0.2V a 3.0V enciende el led verde.
  if(V2<0.1){
    digitalWrite(ledPinVerde, LOW);
    digitalWrite(LedPinAmarillo, LOW);
    digitalWrite(LedPinRojo, LOW);
  }
  if(V2>=0.1 && V2<=3.0){
    digitalWrite(ledPinVerde, HIGH);
    digitalWrite(LedPinAmarillo, LOW);
    digitalWrite(LedPinRojo, LOW);
  }
  // Si el V= 3.0V entonces enciende el led amarillo y el led verde se apaga.
  if (V2>3.0 && V2<=4.0){
    digitalWrite(ledPinVerde, LOW);
    digitalWrite(LedPinAmarillo, HIGH);
    digitalWrite(LedPinRojo, LOW);
  }
  // Si el V= 4.0V se enciende el led rojo y el led amarillo se apaga.
  if (V2>=4.0){
    digitalWrite(ledPinVerde, LOW);
    digitalWrite(LedPinAmarillo, LOW);
    digitalWrite(LedPinRojo, HIGH);
  }
  Serial.print(V2);
  Serial.println("V ");
}

More projects by albertoarangurenp