i need my circuit LEDs to do those things shown in hw.pdf videos. this is using Arduino and a breadboard. I have the circuit built correctly.
hw part 1: https://www.youtube.com/watch?v=o8CEnFgwg7k part 2: https://www.youtube.com/watch?v=jOu-avl-nkI part 3: https://www.youtube.com/watch?v=H-C-sAu3KLs https://www.youtube.com/watch?v=o8CEnFgwg7k https://www.youtube.com/watch?v=jOu-avl-nkI https://www.youtube.com/watch?v=H-C-sAu3KLs hw sample code // The following global variables are used to implement SynchSM // functionality using the Arduino API. In contrast the zyBook, // the Arduino API does not provide the programmer with direct // access to Timer Interrupt functions. const unsigned long period = 1000; unsigned long lastRan; const int b_size = 7; const int b[b_size] = {2, 3, 4, 5, 9, 10, 11}; void setup(){ // Default Arduino Function // Initialize LEDs for(int i = 0; i < b_size;="" i++)="" {="" pinmode(b[i],="" output);="" }="" serial.begin(9600);="" lastran="0;" }="" enum="" states{init,="" s0,="" s1}="" state="INIT;" the="" tick()="" function="" is="" similar="" in="" principle="" to="" zybooks="" if="" you="" find="" it="" confusing,="" draw="" the="" corresponding="" synchsm="" diagram.="" void="" tick(){="" state="" transitions="" switch(state){="" case="" init:="" state="S0;" break;="" case="" s0:="" state="S1;" break;="" case="" s1:="" state="S0;" break;="" default:="" should="" never="" get="" here="" break;="" }="" state="" actions="" switch(state){="" case="" init:="" break;="" case="" s0:="" for(int="" i="0;"><4;i++){ digitalwrite(b[i],low);="" }="" break;="" case="" s1:="" for(int="" i="0;">4;i++){><4;i++){ digitalwrite(b[i],high);="" }="" break;="" default:="" should="" never="" get="" here="" break;="" }="" }="" void="" loop(){="" default="" arduino="" function="" we="" track="" time="" explicitly="" in="" the="" loop()="" function,="" which="" is="" different="" that="" the="" timer="" interrupt="" mechanism="" introduced="" in="" the="" zybook="" if="" ((millis()="" -="" lastran)=""> period) { Tick(); lastRan = millis(); } } hw assignment explanation We have invented time! With this newfound technology we shall combine it with state machines. The sample code below shows an example of a SynchSM. This implementation is somewhat naive compared to real-time task scheduling in the real world, but that is beyond the scope of this class. You will use the millis() function to measure time. Read the sample code to understand how you use a SynchSM for Arduino. The zyBooks Timer Interrupt mechanism is not compatible with Arduino. Pre-lab ● Assemble your kit using the circuit diagram ● Run the sample code ● The sample code should blink all LEDs on/off using a 1000 ms period. ● If the sample code works: ○ Create a video of the output and put the link to it in your report ○ Submit this report to the lab 4 gradescope as a pdf before Friday 5pm (You don't need to submit the code) ○ Gradescope allows unlimited submissions up until the late deadline (Sunday at 11:59 pm) ● If the sample code doesn't work ○ Create a video of the output. ○ Email your Teaching Assistant and link the video immediately, and no later than Friday at 5:00 pm. ● Essentially, you must demonstrate proof that your hardware is working before Friday at 5:00 pm, or that you have contacted your Teaching Assistant. Sample Code Demo Video: https://youtu.be/It4jx2nvDUI Links to an external site. // The following global variables are used to implement SynchSM // functionality using the Arduino API. In contrast the zyBook, // the Arduino API does not provide the programmer with direct // access to Timer Interrupt functions. https://youtu.be/It4jx2nvDUI https://youtu.be/It4jx2nvDUI const unsigned long period = 1000; unsigned long lastRan; const int b_size = 7; const int b[b_size] = {2, 3, 4, 5, 9, 10, 11}; void setup(){ // Default Arduino Function // Initialize LEDs for(int i = 0; i < b_size;="" i++)="" {="" pinmode(b[i],="" output);="" }="" serial.begin(9600);="" lastran="0;" }="" enum="" states{init,="" s0,="" s1}="" state="INIT;" the="" tick()="" function="" is="" similar="" in="" principle="" to="" zybooks="" if="" you="" find="" it="" confusing,="" draw="" the="" corresponding="" synchsm="" diagram.="" void="" tick(){="" state="" transitions="" switch(state){="" case="" init:="" state="S0;" break;="" case="" s0:="" state="S1;" break;="" case="" s1:="" state="S0;" break;="" default:="" should="" never="" get="" here="" break;="" }="" state="" actions="" switch(state){="" case="" init:="" break;="" case="" s0:="" for(int="" i="0;"><4;i++){ digitalwrite(b[i],low);="" }="" break;="" case="" s1:="" for(int="" i="0;">4;i++){><4;i++){ digitalwrite(b[i],high);="" }="" break;="" default:="" should="" never="" get="" here="" break;="" }="" }="" void="" loop(){="" default="" arduino="" function="" we="" track="" time="" explicitly="" in="" the="" loop()="" function,="" which="" is="" different="" that="" the="" timer="" interrupt="" mechanism="" introduced="" in="" the="" zybook="" if="" ((millis()="" -="" lastran)=""> period) { Tick(); lastRan = millis(); } } Notes: ● You are allowed and encouraged to create helper functions ● You are allowed to define any variables and data structures that you need ● Do not call the delay() function inside your SynchSMs! ○ This should finally make sense ● If you set your period to be too small, you may observe unpredictable timing behavior Parts & Wiring Wiring Diagram Parts used ● 4x LEDs ● 1x RGB LED ● 7x 220 resistors ● 1x Photoresistor ● 1x Potentiometer ● Wires Exercises Exercise 1: Light Cycle Demo Video: https://youtu.be/o8CEnFgwg7k Links to an external site. https://youtu.be/o8CEnFgwg7k https://youtu.be/o8CEnFgwg7k This exercise demonstrates how the period controls time-oriented system behavior. Problem: Create a system that lights up the four LEDs as follows: ● The system has a 1 second (1000 ms) period ● Exactly one LED will be lit at all times ● The leftmost LED is lit initially ○ After each Tick(), the lit LED moves one position to the right ● When the rightmost LED is lit, the system changes direction ○ After each Tick(), the lit LED moves one position to the left ● The cycle repeats indefinitely. Exercise 2: Controlable Light Cycle Demo: https://youtu.be/jOu-avl-nkI Links to an external site. Problem: You will enhance the Light Cycle from Exercise #1 by adjusting the speed at which the lit LED changes ● When initialized, the system behaves exactly the same as in Exercise #1, but with a 500 ms period ● Use the potentiometer to adjust the speed at which the lit LED changes ○ The fastest speed of the light cycle is to change the lit LED every 100 ms ○ The slowest speed of the light cycle is to change the lit LED every 500 ms ● You get to determine the period of the system ○ You will receive full credit as long as the system functions properly ○ We will discuss trade-offs involving different system periods later in the quarter. Exercise 3: Sampling Demo: https://youtu.be/H-C-sAu3KLs Links to an external site. Problem: You will design a system that samples inputs from the potentiometer and photoresistor every 100 ms. https://youtu.be/jOu-avl-nkI https://youtu.be/jOu-avl-nkI https://youtu.be/H-C-sAu3KLs https://youtu.be/H-C-sAu3KLs ● After each sample, the system will display the photoresistor reading on the 4 LEDs and the potentiometer on the RGB LED ● Photoresistor: ○ When the photoresistor is covered, none of the LEDs will be lit up ○ When you shine light on the photoresistor (e.g., daylight, a light in the room), more LEDs will light up ○ When you shine a very strong light on the photoresistor (e.g., the flashlight on a phone), all of the LEDs will light up to indicate maximum brightness. ○ You will need to determine appropriate threshold values for your system based on your environment; thresholds will be diferent for everyone ● Potentiometer: ■ When the potentiometer is turned all the way down, the RGB LED will be turned off ■ As you turn the potentiometer up, the RGB LED will change color, from red, to purple, to white ■ You will need to use the map() function again ○ the reading from the potentiometer will be displayed on the RGB LED when the potentiometer is turned all the way down the LED will be off. as you turn the potentiometer up it will go from red to purple to white (you will need to use the map function again) ● Hint: As you are sampling every 100 ms, you may want to use separate states for sampling and updating the display; however, this means that your system period will need to be faster than 100 ms, because there will multiple Tick()s between samples: ○ Sample, Update-Display, Sample, Update-Display, ... ● The period that you choose will depend in part on the number of states that you have in the state machine and the number of Tick()s between sampling. ● Warning: You are not allowed to use the delay() function in this exercise. ○ Any submission that uses delay() is subject to a severe reduction in points.4;i++){>4;i++){>