embedded c doubt | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

embedded c doubt

The below code is not working. In this program, if I press Swich1(PORTK PK1 pin of Arduino Mega), and then if I press Switch2 , led 0 to 3 (whichare connected at pins 0 to 3 of port F of Arduino mega) should blink one by one for each pressing of switch. If I press SW2 switch two times, then while pressing SW1 switch, led 4 to 7 should blink one by one. But first case is working. second case is not working. Pls help to correct the program. Thanks. void setup() { DDRF =0xFF; DDRK = 0x00; volatile long i,j,m; j=0; m=0; while(1){ if((PINK & 0x02) == 0x02) //for(i=0;i<1000;i++); { j=1; if (j/2) { if((PINK & 0x01) == 0x01){ m++; for(i=0;i<50000;i++);} if(m==1) PORTF =0x01; else if(m==2) PORTF=0x02; else if(m==3) PORTF=0x04; else if (m==4){ PORTF = 0x08; m=0; } } if(j%2){ if((PINK & 0x01) == 0x01) // for(i=0;i<20000;i++); { m++; for(i=0;i<50000;i++);} if(m==1) PORTF =0x01; else if(m==2) PORTF=0x02; else if(m==3) PORTF=0x04; else if (m==4){ PORTF = 0x08; m=0; } }}}} void loop() { // put your main code here, to run repeatedly: }

21st Nov 2022, 5:12 PM
Iyyappan.C
Iyyappan.C - avatar
1 Answer
+ 1
This comunity can be better for such a help: https://wokwi.com/
21st Nov 2022, 5:45 PM
JaScript
JaScript - avatar