#include “LPD8806.h”
#include “SPI.h”
#include <Adafruit_NeoPixel.h>
// Number of RGB LEDs in strand:
int nLEDs = 12;
// Chose 2 pins for output; can be any valid output pins:
int dataPin = 2;
int clockPin = 3;
int inputPin = 4; // choose input pin (for FRONT Infrared sensor)
int inputPin2 = 5; // choose input pin (for BACK Infrared sensor)
int val = 0; // variable for reading the pin status – FRONT
int val2 = 0; // variable for reading the pin status – BACK
LPD8806 strip = LPD8806(nLEDs, dataPin, clockPin);
// You can optionally use hardware SPI for faster writes, just leave out
// the data and clock pin parameters. But this does limit use to very
// specific pins on the Arduino. For “classic” Arduinos (Uno, Duemilanove,
// etc.), data = pin 11, clock = pin 13. For Arduino Mega, data = pin 51,
// clock = pin 52. For 32u4 Breakout Board+ and Teensy, data = pin B2,
// clock = pin B1. For Leonardo, this can ONLY be done on the ICSP pins.
//LPD8806 strip = LPD8806(nLEDs);//Force Sensor to Light Fade
//turn on the serial statements to DEBUG
//add in mapping statements to make for a better response
uint32_t red = strip.Color(255, 0, 0);
uint32_t green = strip.Color(0, 255, 0);
uint32_t yellow = strip.Color(255, 100, 0);
uint32_t blue = strip.Color(0, 0, 255);
uint32_t purple = strip.Color(80, 0, 80);
uint32_t orange = strip.Color(0, 165, 255);
//byte ForceSensePin;
int ForceSensorValue1;
int ForceSensorValue2;
int ForceSensorValue3;
int ForceSensorValue4;
int i;
//float voltage;
int voltage1;
int voltage2;
int voltage3;
int voltage4;
int voltage5;
int voltage6;
int wait = 10;
void setup() {
Serial.begin(9600);
// Start up the LED strip
strip.begin();
// Update the strip, to start they are all ‘off’
strip.show();
pinMode(inputPin, INPUT); // declare Infrared sensor as input
pinMode(inputPin2, INPUT); // declare Infrared sensor as input
}
void loop() {
val2 = digitalRead(inputPin2); // read input value BACK
val = digitalRead(inputPin); // read input value FRONT
ForceSensorValue1 = analogRead(A0);
ForceSensorValue2 = analogRead(A1);
ForceSensorValue3 = analogRead(A2);
ForceSensorValue4 = analogRead(A3);
voltage1 = (ForceSensorValue1 * (5.0 / 1023.0)) * 100;
voltage1 = map(voltage1, 0, 480, 0, 255);
// Serial.print(“Pressure1 = “);
// Serial.print(voltage1);
// Serial.println(“”);
// delay(wait);
voltage2 = (ForceSensorValue2 * (5.0 / 1023.0)) * 100; //voltage1 = voltage * 100;
voltage2 = map(voltage2, 0, 480, 0, 255);
// Serial.print(“Pressure2 = “);
// Serial.print(voltage2);
// Serial.println(“”);
// delay(wait);
voltage3 = (ForceSensorValue3 * (5.0 / 1023.0)) * 100; //voltage1 = voltage * 100;
voltage3 = map(voltage3, 0, 480, 0, 255);
// Serial.print(“Pressure3 = “);
// Serial.print(voltage3);
// Serial.println(“”);
// delay(wait);
voltage4 = (ForceSensorValue4 * (5.0 / 1023.0)) * 100; //voltage1 = voltage * 100;
voltage4 = map(voltage4, 0, 480, 0, 255);
// Serial.print(“Pressure4 = “);
// Serial.print(voltage4);
// Serial.println(“”);
// delay(wait);
// else if (voltage3 >30 || voltage4 >30) {
// }
if (val2 == LOW) { // check if the input is HIGH
//strip.setPixelColor(4,red);//red
strip.setPixelColor(5, purple);//orange
strip.setPixelColor(6,purple);//orange
// strip.setPixelColor(7,red);//red
strip.show();
Serial.println(“front_triggered”);
// delay(wait);
}
else if (val == LOW) { // check if the input is HIGH
strip.setPixelColor(4,red);//red
//strip.setPixelColor(5,red);//red
//strip.setPixelColor(6,red);//red
strip.setPixelColor(7,red);//red
strip.show();
Serial.println(“back_triggered”);
delay(wait);
}
else if (voltage1 >30 || voltage4 >30) {
strip.setPixelColor(0,blue);//Blue:
strip.setPixelColor(1,blue);//Blue:
strip.setPixelColor(10,blue);//Blue:
strip.setPixelColor(11,blue);//Blue:
strip.show();
delay(wait);
}
else if (voltage2 >30 || voltage3 >30) {
// strip.show();
strip.setPixelColor(2,yellow);//yellow:
strip.setPixelColor(3,yellow);//yellow:
strip.setPixelColor(8,yellow);//yellow:
strip.setPixelColor(19,yellow);//yellow:
strip.show();
delay(wait);
}
//strip.show();
else {
strip.show();
for(i=0; i<12; i++) {
strip.setPixelColor(i, 0); // Erase pixel, but don’t refresh!
}
}
}