Phys Comp: Week 2 – Analog sensors, Part 1

This week we worked with analog sensors.

For the lab, I was able to correctly set up the breadboard, Arduino, and potentiometer to create my first analog input. I documented along the way.

Then I made a two-input analog switch with two LEDs as output. Here’s the code:

int ledPinGreen = 10; // Green pin
int ledPinRed = 9; // Red pin

int analogFSRLeft = 0; // Left analog input
int analogFSRRight = 1; // Right analog input

int FSRValueLeft = 1; // Value of the left FSR
int FSRValueRight = 1; // Value of the right FSR

void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
}
void loop() {
FSRValueLeft = analogRead(analogFSRLeft); // read the left FSR value
analogWrite(ledPinGreen, FSRValueLeft/4);
Serial.println(FSRValueLeft); // print the FSR value back to the

FSRValueRight = analogRead(analogFSRRight); // read the right FSR value
analogWrite(ledPinRed, FSRValueRight/4);
Serial.println(FSRValueRight);

delay(10); // gives a 10 millisecond delay
}

Leave a Reply

Your email address will not be published.