Arduino, LED On/Off using switch, (Aduino study),

Today, I studied about input signal.
So, my arduino can turn on/off LED by switch.
In the picture, black wire works the role of switch.

const int LED = 13;
const int BUTTON = 7;

int val = 0;
int old_val = 0;
int sw_OnOff=0;

void setup(){
  pinMode(LED, OUTPUT);
  pinMode(BUTTON, INPUT);

void loop(){
  val = digitalRead(BUTTON);
  if((old_val==LOW) && (val==HIGH)){
  old_val = val;
  digitalWrite(LED, sw_OnOff);

But I still don't know why it need register and why the wire connect with there??
But, it is very fun~

No comments:

Post a Comment