So as seen in the picture, i just want the led to be off when the switch is of. And blink when it is on. I feel like I have tried everything. Pin 2 is working as an output, but I cannot seem to understand the input function.
(Could only include one picture as a new user)
EDITED by J-M-L:
with properly formatted (bad) code and not the crappy image for future reference on how to post.
int test = 13;
int test2 = 7;
int readpin = 2;
void setup() {
// put your setup code here, to run once:
pinMode (test, OUTPUT) ;
pinMode (test2, OUTPUT) ;
pinMode (readpin, INPUT) ;
}
void loop() {
if (digitalRead(readpin == HIGH)) {
digitalWrite(test, HIGH);
digitalWrite (test2, HIGH);
delay(100);
digitalWrite(test, LOW);
digitalWrite(test2, LOW);
delay(100);
}
if (digitalRead (readpin == LOW)) {
digitalWrite(test2, LOW);
digitalWrite(test, LOW) ;
}
}
if(digitalRead(readpin) == HIGH) {
...
} else { // if it's not HIGH then it's LOW
...
}
you might have to deal with bouncing and hopefully you have an external pull down resistor for your switch? (you could use the builtin pull-up otherwise)
side note: It's beyond me why people would choose to post an image of some text instead of the text itself...