I'm going through an Arduino tutorial book.
Just made a sketch for Arduino to turn on the led when the connected switch is pressed.
The code the book wrote was
void setup() {
// put your setup code here, to run once:
pinMode(4, OUTPUT);
pinMode(2,INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
int button=digitalRead(2);
digitalWrite(4,button);
delay(10);
}
I tried putting digitalRead directly into digitalWrite.
like
digitalWrite(4,digitalRead(2));
The led turned on like the book's code, but led was much dimmer.
I want to know why it does that.
Also, the book says they put delay(10) to make the loop() don't run too quickly.
I took out the delay(10) and it worked fine. Does Arduino die quicker if the code inside loop too quickly?