This is a test to see wich ARDUINO UNO pin should I use for input.
I don't understand why only ARDUINO pin 2, 4 and 7 work correctly
for input.
When you say :
cont int buttonPin = 3
Pin3 doesn't work as an input. But Pin2 does
Here's the code and the Circuit in attachment.
Best Regards
George
const int buttonAPin = 3; //premier button RED
const int buttonBPin = 4; //deuxieme button YELLOW
const int buttonCPin = 5; //troisieme button GREEN
const int ledAPin = 8;
const int ledBPin = 9;
const int ledCPin = 10;
// Variable will change:
int buttonAState = 0;
int buttonBState = 0;
int buttonCState = 0;
void setup() {
// Initialize the LED pinas an output:
pinMode(ledAPin, OUTPUT);
pinMode(ledBPin, OUTPUT);
pinMode(ledCPin, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
buttonAState = digitalRead(buttonAPin);
buttonBState = digitalRead(buttonBPin);
buttonCState = digitalRead(buttonCPin);
The code needed to be change as I made some misteaks.
It looks good but when the Switch 02 is on all Leds 10 11 12 13 are ON
code:
const int buttonAPin = 0;
const int buttonBPin = 1;
const int buttonCPin = 2;
const int buttonDpin = 3;
const int buttonEpin = 4;
const int buttonFpin = 5;
const int buttonGpin = 6;
const int buttonHpin = 7;
const int ledAPin = 8; // buttonApin 0
const int ledBPin = 9; // buttonBpin 1
const int ledCPin = 10; // buttonCpin 2
const int ledDpin = 11; // buttonDpin 3
const int ledEpin = 12; // buttonEpin 4
const int ledFpin = 13; // buttonFpin 5
// Variable will change:
int buttonAState = 0;
int buttonBState = 0;
int buttonCState = 0;
int buttonDState = 0;
int buttonEState = 0;
int buttonFState = 0;
int buttonGState = 0;
int buttonHState = 0;
//
void setup() {
// Initialize the LED pinas an output:
pinMode(ledAPin, OUTPUT);
pinMode(ledBPin, OUTPUT);
pinMode(ledCPin, OUTPUT);
pinMode(ledDpin, OUTPUT);
pinMode(ledEpin, OUTPUT);
pinMode(ledFpin, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
buttonAState = digitalRead(buttonAPin);
buttonBState = digitalRead(buttonBPin);
buttonCState = digitalRead(buttonCPin);
buttonDState = digitalRead(buttonCPin);
buttonEState = digitalRead(buttonCPin);
buttonFState = digitalRead(buttonCPin);
buttonGState = digitalRead(buttonCPin);
buttonHState = digitalRead(buttonCPin);
Hi dear,
This is a test to see wich ARDUINO UNO pin should I use for input.
I don't understand why only ARDUINO pin 2, 4 and 7 work correctly
for input.
When you say :
cont int buttonPin = 3
Pin3 doesn't work as an input. But Pin2 does
Here's the code and the Circuit in attachment.
Best Regards
George
const int buttonAPin = 3; //premier button RED
const int buttonBPin = 4; //deuxieme button YELLOW
const int buttonCPin = 5; //troisieme button GREEN
const int ledAPin = 8;
const int ledBPin = 9;
const int ledCPin = 10;
// Variable will change:
int buttonAState = 0;
int buttonBState = 0;
int buttonCState = 0;
void setup() {
// Initialize the LED pinas an output:
pinMode(ledAPin, OUTPUT);
pinMode(ledBPin, OUTPUT);
pinMode(ledCPin, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
buttonAState = digitalRead(buttonAPin);
buttonBState = digitalRead(buttonBPin);
buttonCState = digitalRead(buttonCPin);
if (buttonAState == HIGH) {
digitalWrite(ledAPin, HIGH);
} else {
digitalWrite(ledAPin, LOW);
}
if (buttonBState == HIGH) {
digitalWrite(ledBPin, HIGH);
} else {
digitalWrite(ledBPin, LOW);
}
if (buttonCState == HIGH) {
digitalWrite(ledCPin, HIGH);
} else {
digitalWrite(ledCPin, LOW);
}
}
Hi.
I can't see the circuit in attachment.
The problem is probably in the circuit because your code is working for me.
there it is:
It is working for me.
Do you have the simu file?
View and moderate all "Help" comments posted by this user
Mark all as spam, and block user from posting to "Discussion"
Hi dear Santiago,
Here is the repport
Kind Regards
Hi.
Report says everything is ok.
what would be useful is the simu file.
In any case is better to use "fixed Volt." components instead of switches.
Regards.
View and moderate all "Help" comments posted by this user
Mark all as spam, and block user from posting to "Discussion"
Dear Santiago,
The code needed to be change as I made some misteaks.
It looks good but when the Switch 02 is on all Leds 10 11 12 13 are ON
code:
const int buttonAPin = 0;
const int buttonBPin = 1;
const int buttonCPin = 2;
const int buttonDpin = 3;
const int buttonEpin = 4;
const int buttonFpin = 5;
const int buttonGpin = 6;
const int buttonHpin = 7;
const int ledAPin = 8; // buttonApin 0
const int ledBPin = 9; // buttonBpin 1
const int ledCPin = 10; // buttonCpin 2
const int ledDpin = 11; // buttonDpin 3
const int ledEpin = 12; // buttonEpin 4
const int ledFpin = 13; // buttonFpin 5
// Variable will change:
int buttonAState = 0;
int buttonBState = 0;
int buttonCState = 0;
int buttonDState = 0;
int buttonEState = 0;
int buttonFState = 0;
int buttonGState = 0;
int buttonHState = 0;
//
void setup() {
// Initialize the LED pinas an output:
pinMode(ledAPin, OUTPUT);
pinMode(ledBPin, OUTPUT);
pinMode(ledCPin, OUTPUT);
pinMode(ledDpin, OUTPUT);
pinMode(ledEpin, OUTPUT);
pinMode(ledFpin, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
buttonAState = digitalRead(buttonAPin);
buttonBState = digitalRead(buttonBPin);
buttonCState = digitalRead(buttonCPin);
buttonDState = digitalRead(buttonCPin);
buttonEState = digitalRead(buttonCPin);
buttonFState = digitalRead(buttonCPin);
buttonGState = digitalRead(buttonCPin);
buttonHState = digitalRead(buttonCPin);
if (buttonAState == HIGH) {
digitalWrite(ledAPin, HIGH);
} else {
digitalWrite(ledAPin, LOW);
}
if (buttonBState == HIGH) {
digitalWrite(ledBPin, HIGH);
} else {
digitalWrite(ledBPin, LOW);
}
if (buttonCState == HIGH) {
digitalWrite(ledCPin, HIGH);
} else {
digitalWrite(ledCPin, LOW);
}
if (buttonDState == HIGH) {
digitalWrite(ledDpin, HIGH);
} else {
digitalWrite(ledDpin, LOW);
}
if (buttonEState == HIGH) {
digitalWrite(ledEpin, HIGH);
} else {
digitalWrite(ledEpin, LOW);
}
if (buttonFState == HIGH) {
digitalWrite(ledFpin, HIGH);
} else {
digitalWrite(ledFpin, LOW);
}
}
Kind Regards
View and moderate all "Help" comments posted by this user
Mark all as spam, and block user from posting to "Discussion"
Hello,
Happy newyear Santiago