Hello,
I'm a begginner at arduino .I have descided to do my first own program and it is full of mistakes!! .
This problem is quite complicated nd I can't fix it neither on my own neither with my family members...
I have a program that takes a variable and then turns it into a series of leds (using the binary system). My problem is that everythings seems to work but when I upload it the leds are all lit up when they shouldn't...
Here is the code:
struct binary{
bool LED1;
bool LED2;
bool LED4;
bool LED8;
bool LED16;
};
int minuteur = 0;
void light( binary );
binary convert( int);
void setup() {
pinMode(8, INPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
Serial.begin(9600);
}
void loop() {
minuteur = 17;
delay(5000);
Serial.println(minuteur);
binary bin;
/*bin.LED1 = true;
bin.LED2 = false;
bin.LED4 = true;
bin.LED8 = false;
bin.LED16 = true; */
light( bin );
convert (minuteur);
}
binary convert(int minuteur){
binary bin;
minuteur = 4;
delay (5000);
int reste = 0;
bin.LED16,bin.LED8, bin.LED4, bin.LED2, bin.LED1 = LOW;
if (minuteur/16 == 1){
bin.LED16 = true;
reste = minuteur % 16;
}
if ( reste/8 == 1){
bin.LED8 = true;
reste = reste % 8;
}
if ( reste/4 == 1){
bin.LED4 = true;
reste = reste % 4;
}
if (reste/2 == 1){
bin.LED2 = true;
reste = reste % 2;
}
if (reste/1 == 1){
bin.LED1 = true;
reste = reste % 1;
}
return bin;
}
void light(binary bin){
if (bin.LED1){
digitalWrite(13, HIGH);
}
else {
digitalWrite(13, LOW);
}
if (bin.LED2){
digitalWrite(12, HIGH);
}
else {
digitalWrite(12, LOW);
}
if (bin.LED4){
digitalWrite(11, HIGH);
}
else {
digitalWrite(11, LOW);
}
if (bin.LED8){
digitalWrite(10, HIGH);
}
else {
digitalWrite(10, LOW);
}
if (bin.LED16){
digitalWrite(9, HIGH);
}
else {
digitalWrite(9, LOW);
}
}
PS: English isn't my native language so I'm sorry if there are some spelling/vocabulary errors...
PSS: Sorry if the code is not properly formated but it didn't work: it readPreformatted text
when i did it.