// Author: Nien Lam // Date: 09-24-2009 // Title: Double Sensors, Double LED Arrays // Descr: 2 sensors (aka variable resistors), are used to turn on corresponding arrays of LEDs. // Greater force/pressure applied to the sensors will cause more LEDs in the array to turn on. // Analog input pins variable resistors 1 and 2 int r1Pin = 0; int r2Pin = 1; // Analog values from variable resistors 1 and 2 int r1Val = 0; int r2Val = 0; // Min/Max values for resistors, ranges may be flipped based on resistor type int r1ValMin = 0; int r1ValMax = 600; int r2ValMin = 100; int r2ValMax = 40; // LED arrays associated with variable reisistor 1 and 2 int r1LedArr[] = {11, 10, 9, 8}; int r2LedArr[] = {7, 6, 5, 4}; // Size of LED arrays int r1LedArrSize = sizeof(r1LedArr)/sizeof(int); int r2LedArrSize = sizeof(r2LedArr)/sizeof(int); void setup() { // Initialize serial communications at 9600 bps Serial.begin(9600); // Declare the led pin as outputs for (int ii=0; ii < r1LedArrSize; ii++) pinMode(r1LedArr[ii], OUTPUT); for (int ii=0; ii < r2LedArrSize; ii++) pinMode(r2LedArr[ii], OUTPUT); } void loop() { // Reset LED arrays to LOW for (int ii=0; ii < r1LedArrSize; ii++) digitalWrite(r1LedArr[ii], LOW); for (int ii=0; ii < r2LedArrSize; ii++) digitalWrite(r2LedArr[ii], LOW); // Turn on LED array 1 based on forced applied to resistors r1Val = analogRead(r1Pin); int r1Force = map(r1Val, r1ValMin, r1ValMax, 0, 4); for (int ii=0; ii < r1LedArrSize; ii++) { if (r1Force > ii) digitalWrite(r1LedArr[ii], HIGH); } // Turn on LED array 1 based on forced applied to resistors r2Val = analogRead(r2Pin); int r2Force = map(r2Val, r2ValMin, r2ValMax, 0, 4); for (int ii=0; ii < r2LedArrSize; ii++) { if (r2Force > ii) digitalWrite(r2LedArr[ii], HIGH); } //Serial.println(r1Val); //Serial.println(r2Val); // Add a delay delay(200); }