I would expect this code to print: either 'inside while loop' (if pin 2 is false) or nothing, followed by 'Break.' over and over again. Io_cfg. The while(1) loop executes once, every time loop() is called, printing or not, depending on the state of pin2. If (presentTime - previousTime_Red >= eventTime_Red) // initialize the gpio configuration structure PinMode(LED_Green, OUTPUT) //configure pin 21 to behave as an outputĭigitalWrite(LED_Red, LOW) //have the red LED initially offĭigitalWrite(LED_Green, LOW) //have the green LED initially off The while loop () is the conditional loop that continues to execute the code inside the parentheses until the specified condition becomes false. PinMode(LED_Red, OUTPUT) //configure pin 15 to behave as an output Interrupts can slightly disrupt the timing of code, however. Some functions will not work while interrupts are disabled, and incoming communication may be ignored. Interrupts allow certain important tasks to happen in the background and are enabled by default. Task 2: turn on green LED for 1 second, execute every 10 secondsĬonst long eventTime_Red = 4000 //execute every 4 secondsĬonst long eventTime_Green = 10000 //execute every 10 secondsĬonst long red_period = 1000 //keep red LED on for 1 secondĬonst long green_period = 1000 //keep green LED on for 1 secondĬonst byte LED_Red = 15 //LED red connected to pin 15Ĭonst byte LED_Green = 21 //LED green connected to pin 21 Re-enables interrupts (after they’ve been disabled by noInterrupts (). Task 1: turn on red LED for 1 second, execute every 4 seconds Apart from that, my code produces correct results (see code below). But in reality, with my code, only the red LED turns on at second 20. As you can see, at second 20, tasks 1 and 2 should execute at the same time, i.e.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |