I am taking classes in coding for arduino, for my study. However we cant simply use the program that an ardiuno comes with, we have to hard code everything. This is all fine but we got a task to make 2 LED's blink. one at 1 Hz one at 2 Hz. My idea was to have a while(1) loop with a simple counter that restarts every quarter a second. Than whenever the right number comes up turn on or of the LED.
So this is my code:
A quik note, DDRB is me assigning the port it has to send a signal to, and PORTB is the signal. Since my arduino has a 5 V running trough it, PORTB = 0b00000000; means it gets turned on and PORTB = 0b10000000; means it gets turned off.Code:#include <avr/io.h>#include <util/delay.h> int main(void) { int in_what_loop = 0; while(1) { if(in_what_loop == 4) { in_what_loop = 0; } in_what_loop = in_what_loop + 1; if(in_what_loop == 1) { DDRB = 0b10000000; PORTB = 0b00000000; DDRB = 0b01000000; PORTB = 0b00000000; } if(in_what_loop == 2) { DDRB = 0b10000000; PORTB = 0b10000000; } if(in_what_loop == 3) { DDRB = 0b10000000; PORTB = 0b00000000; DDRB = 0b01000000; PORTB = 0b10000000; } if(in_what_loop ==4) { DDRB = 0b10000000; PORTB = 0b10000000; } _delay_ms(250); } }
Also this code is writen in C.
With this script only the bottom one blinks and i dont know why. Anyone know anything?