In this Arduino lab you will write a program that gets input from the light sensor in the Adafruit Circuit Playground and uses it as an controller for a Processing program
Connect the Circuit Playground to your computer with a USB cord. Open Processing. You will need to install a library (you only need to do this once). Choose Sketch | Import Library | Add Library. Type Arduino in the text field labeled Filter. Choose Arduino (Firmata) and click Install.
Copy and paste the following program
import processing.serial.*;
import cc.arduino.*;
Arduino arduino;
public void setup() {
size(500, 500);
arduino = new Arduino(this, Arduino.list()[0], 57600); //change the [0] to a [1] or [2] etc. if your program doesn't work
}
public void draw() {
background(192);
int y = arduino.analogRead(5);
System.out.println(y);
ellipse(250, 2*y, 50, 50);
}
Run the program. Pass your hand over the light sensor labeled with a picture of an eye on the Circuit Playground. You should see an ellipse move up and down as the light sensor changes values. Higher values mean more light. The light sensor is circled in the picture below. On some machines, you may need to change the last line in setup()
to get the program to work correctly.
Using the sample program as a guide, write your own program that uses the light sensor. Your program doesn't have to work or look like any other. Have fun and be creative!
When you are happy with your program, have a friend make a short video of you interacting with your virtual pet. Convert the video to an animated gif using a free converter like ezgif.com. Use ezgif's cut video or a similar option to edit your video to under 10 seconds and less than 25MB. Upload your animated gif to your VirtualPet repository. Submit the link to your gif to Google Classroom. See Mr. Simon's example animated gif below.
Mr. Simon's virtual pet penguin animated gif
None yet!