[NOT FINAL] Lab #5: Building and programing the mood ring PCB with randomness

This lab builds on Lab 4 to make a device that flashes an RGB LED in an interesting pattern in a way that depends on the ambient temperature. The goal is for you to continue to master combining multiple elements of embedded system architecture while also exploring random number generation.

Part 0: Building and programming the Mood Ring PCB

Begin by assembling your mood ring PCB and programming it with the code you developed for Lab

  1. PAY ATTENTION to the values of resistance you use with the RGB LED. If you make them too small, it may be fine when running from USB power, but cause problems when running from the battery.

Part 1: Adding Randomness

Next, we will add some randomness to the colors generated by the thermometer. Implement the function int rand32(int seed), which returns a number between 0 and 31. The function should included one or more static variables that maintain state across function calls such that each time the function is called, the return value is different. If the int seed argument is zero, it should be ignored. Otherwise, it should be used to initialize the state variables of the function. The expectation is that the sequence of values returned following a call with the same seed value will be the same.

Now, you will change the architecture of your code so that rather than the temperature deterministically setting the value of the R and B colors, it causes the dynamics of a random walk through color space to change. The logic should be as follows:

  1. Each cycle of the main timing loop, generate 2 random numbers. Rescale them such that they are between -15 and +15 (this is assuming you have 255 possible levels of intensity). This will give two numbers r and b.
  2. Measure the temperature.
  3. If the current temperature is colder than it was the last cycle, subtract 8 from r and add 8 to b. If it is warmer, subtract 8 from b and add 8 to r.
  4. Update the PWM intensities with r and b.

BONUS: If you have implemented control of the green channel, additionally randomly change the intensity of the green LED.

BONUS: Create a library which contains the rand32() function, compile it independently, and then include it into your project. (This involves putting the function definition in its own file, creating a header file that contains the function declaration, and compiling it as a library. You then include the header and the compiled library into your project.)

BONUS: If you added the external temperature sensor to your PCB, re-implement the temperature measurement using it.

Save your control code as random_mood_ring.c. Create a demo video that shows the shifting colors. You should demonstrate how changing the temperature causes changes in the color patterns. Upload your code and the video URL to owlspace. If you want to claim the library bonus, you should also upload a screenshot of your CCS project with the library included. If you want to claim the external sensor bonus, make sure you point out how you used it to measure temperature. Finally, if you used the SMD RGB LED, mention that as well.