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! Submit the .pde file to Google Classroom when you are happy with your program. You should be able to find it in the My Documents | Processing folder. Don't forget to click the Mark as done button.
Back to school night is Thursday September 19. Let me know if I can use your program at back to school night.
Feel free to experiment with other aspects of the Arduino. Here's a sample program the will print the values of 16 inputs
import processing.serial.*;
import cc.arduino.*;
Arduino arduino;
public void setup() {
size(100, 100);
arduino = new Arduino(this, Arduino.list()[0], 57600);
}
public void draw() {
background(192);
for(int i = 0; i < 16; i++)
System.out.print(i+" "+arduino.analogRead(i) + "\t");
System.out.println();
}