Hi:
Just trying a script with buttons and led's
Should think its easy, but i cant get the leds to work.
If i use the old blink script all is good
The buttons work i get conf in the monitor.
Led 1 works but not 2,3 and 4..
think i tested everything ,,,
here is the code
// constants won't change. They're used here to set pin numbers:
const int buttonPin1 = 15; //From Left
const int buttonPin2 = 16;
const int buttonPin3 = 17;
const int buttonPin4 = 45;
const int buttonPin5 = 39;
const int ledPin1 = 26;
const int ledPin2 = 25;
const int ledPin3 = 24;
const int ledPin4 = 23;
// variables will change:
int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
int buttonState5 = 0;
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
pinMode(buttonPin1, INPUT_PULLUP);
pinMode(buttonPin2, INPUT_PULLUP);
pinMode(buttonPin3, INPUT_PULLUP);
pinMode(buttonPin4, INPUT_PULLUP);
pinMode(buttonPin5, INPUT_PULLUP);
Serial.begin(9600);
// LED TEST
// read the state of the pushbutton value:
}
void loop() {
// read the state of the pushbutton value:
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
buttonState3 = digitalRead(buttonPin3);
buttonState4 = digitalRead(buttonPin4);
buttonState5 = digitalRead(buttonPin5);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState1 == LOW) {
delay(200);
digitalWrite(ledPin1, HIGH);
Serial.println(F("button 1")); }
if (buttonState2 == LOW) {
delay(200);
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, HIGH);
Serial.println(F("button 2")); }
if (buttonState3 == LOW) {
delay(200);
Serial.println(F("button 3"));
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, HIGH);
}
if (buttonState4 == LOW) {
delay(200);
Serial.println(F("button 4"));
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, HIGH);
}
if (buttonState5 == LOW) {
delay(200);
Serial.println(F("button 5"));
digitalWrite(ledPin4, LOW);
digitalWrite(ledPin1, HIGH);
}
}// LOOP
tore
Just trying a script with buttons and led's
Should think its easy, but i cant get the leds to work.
If i use the old blink script all is good
The buttons work i get conf in the monitor.
Led 1 works but not 2,3 and 4..
think i tested everything ,,,
here is the code
// constants won't change. They're used here to set pin numbers:
const int buttonPin1 = 15; //From Left
const int buttonPin2 = 16;
const int buttonPin3 = 17;
const int buttonPin4 = 45;
const int buttonPin5 = 39;
const int ledPin1 = 26;
const int ledPin2 = 25;
const int ledPin3 = 24;
const int ledPin4 = 23;
// variables will change:
int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
int buttonState5 = 0;
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
pinMode(buttonPin1, INPUT_PULLUP);
pinMode(buttonPin2, INPUT_PULLUP);
pinMode(buttonPin3, INPUT_PULLUP);
pinMode(buttonPin4, INPUT_PULLUP);
pinMode(buttonPin5, INPUT_PULLUP);
Serial.begin(9600);
// LED TEST
// read the state of the pushbutton value:
}
void loop() {
// read the state of the pushbutton value:
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
buttonState3 = digitalRead(buttonPin3);
buttonState4 = digitalRead(buttonPin4);
buttonState5 = digitalRead(buttonPin5);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState1 == LOW) {
delay(200);
digitalWrite(ledPin1, HIGH);
Serial.println(F("button 1")); }
if (buttonState2 == LOW) {
delay(200);
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, HIGH);
Serial.println(F("button 2")); }
if (buttonState3 == LOW) {
delay(200);
Serial.println(F("button 3"));
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, HIGH);
}
if (buttonState4 == LOW) {
delay(200);
Serial.println(F("button 4"));
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, HIGH);
}
if (buttonState5 == LOW) {
delay(200);
Serial.println(F("button 5"));
digitalWrite(ledPin4, LOW);
digitalWrite(ledPin1, HIGH);
}
}// LOOP
tore