- Today we're going to work with classes and and arrays of objects. Together, we'll define a custom class and use it to make an interactive animating display.
- For homework, customize the program by handling at least one additional mouse event and two other key events.
- Hints:
- Event handling. Unlike last week, do not use
noLoop()
which will stop the animation. Your rendering (drawing) should remain state-driven and not in the event handler functions.
- This is due no later than Tuesday, October 29th, before our next after-fall-break lab.
- Add comments to reflect your name, the date, what the program does and how to use it; e.g. what mouse and key events are handled.
- Submit on Moodle.
- Pick up a 10K resistor, an RGB LED, and a speaker. We'll use these in today's labs, please add them to your kit.
- RGB LED: Work through https://learn.adafruit.com/adafruit-arduino-lesson-3-rgb-leds/ Modify the program to cycle through the Vassar color palette as described in the Vassar Visual Style Guide. Show either me or Elias when you have finished.
- SPEAKER: Open File/Examples/Digital/tone-melody. You'll notice the frequencies are being sent to pin 8. Change that to pin 11, by adding a global definition line as follows to the beginning of the code:
const int speakerPin = 11;
- Then replace the hard-coded 8's with speaker pin in the
tone
and noTone
calls. - Can you play another melody—something very short? For reference; middle c is c4, high c is c5, etc... You may pair up on this exercise.
- PHOTO CELL: Work through the photocell tutorial at https://learn.adafruit.com/photocells/overview. If your circuit is wired correctly; as you cover the photocell, the LED will grow brighter.
- Notice this line of code:
map(photocellReading, 0, 1023, 0, 255);
- That maps values from 0-1023 to 0-255. The reality is that we rarely see the whole 1024 possible values. Look at the serial monitor and see what range of raw values you see. It will be different for each photocell and the light interacting with your Metro. In my office during the day, I saw values from 620-970.
map(photocellReading, 600, 999, 0, 255);
- By changing the map call as shown above, I saw a much greater range on the red LED. Customize the line for your Metro.
- Can you think of a way you could calibrate the program in a more elegant fashion? If you have time implement it.