Arduino Tutorial - Turn LED ON/OF using Pushbutton

preview_player
Показать описание
Turn LED ON/OF using Pushbutton
Рекомендации по теме
Комментарии
Автор

The second example had errors when I attempted it, so I tweaked the code to work for an attiny85
the only difference from the vid was that I had to press the pushbutton for a long second to turn on/off
wasn't an issue (3days into learning this stuff so if it's sloppy, that's why.)

int ledPin1 = 0;
int ledPin2 = 3;
int ledPin3 = 7;
int keyPin = 4;
boolean ledOn = false;
void setup()
{
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(keyPin, INPUT_PULLUP);
}
void loop(){

if (digitalRead(keyPin) == true) {
ledOn = !ledOn;
}digitalWrite(ledPin1, ledOn);
delay(500);
digitalWrite(ledPin2, ledOn);
delay(500);
digitalWrite(ledPin3, ledOn);
}

brianluna
Автор

nothing wrong with the 2nd example just add delay(500); after ledOn = !ledOn;

Alifeman
Автор

The code dos not work doenot wast jour tame

wiehancoetzee