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.
Begin by assembling your mood ring PCB and programming it with the code you developed for Lab
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:
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.