Hello. I was wondering how I could make an LED blink and then stop it, when pressing a certain key on the keyboard. Similar to a power switch. Any ideas for a source code ? Thank you !
Hello. I was wondering how I could make an LED blink and then stop it, when pressing a certain key on the keyboard. Similar to a power switch. Any ideas for a source code ? Thank you !
Yes you can but my advice it's the same from my other partners (paul and shabaz). I can put here a little piece of pseudo-code to guide you.
bool last_state_on = false; void setup(){ pinMode(pin_to_stop_blink, INPUT); pinMode(pin_led, OUTPUT); } void loop(){ if(digitalRead(pin_to_stop_blink) == LOW) //ACTIVATE IN HIGH { if(last_state_on == false){ last_state_on = true; digitalWrite(pin_led,HIGH); }else{ last_state_on = false; digitalWrite(pin_led,LOW); } }else{ digitalWrite(pin_led,LOW); } }
The code is tooooooo simply but i think that for the first step is better go piecemeal. If you continue with Arduino you will discover a many things to improve in this code.
Yes you can but my advice it's the same from my other partners (paul and shabaz). I can put here a little piece of pseudo-code to guide you.
bool last_state_on = false; void setup(){ pinMode(pin_to_stop_blink, INPUT); pinMode(pin_led, OUTPUT); } void loop(){ if(digitalRead(pin_to_stop_blink) == LOW) //ACTIVATE IN HIGH { if(last_state_on == false){ last_state_on = true; digitalWrite(pin_led,HIGH); }else{ last_state_on = false; digitalWrite(pin_led,LOW); } }else{ digitalWrite(pin_led,LOW); } }
The code is tooooooo simply but i think that for the first step is better go piecemeal. If you continue with Arduino you will discover a many things to improve in this code.