Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
//Include neopixel Library
#include <SoftwareSerial.h>
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN5 5
Adafruit_NeoPixel strip1 = Adafruit_NeoPixel(6, PIN5, NEO_RGB + NEO_KHZ800);
const int lightstrip1 = 5;
const int FSR1 = A0;
const int FSR2 = A1;
const int FSR3 = A2;
const int softwareTx = 8;
const int softwareRx = 7;
SoftwareSerial s7s(softwareRx, softwareTx);
char tempString[10]; // Will be used with sprintf to create strings
int score = 0;
int pressure1;
int pressure2;
int pressure3;
int mappedP1;
int mappedP2;
int mappedP3;
int hits = 0;
void setup() {
// put your setup code here, to run once:
pinMode(FSR1, INPUT);
pinMode(FSR2, INPUT);
pinMode(lightstrip1, OUTPUT);
strip1.begin();
strip1.show();
Serial.begin(9600);
s7s.begin(9600);
clearDisplay();
}
void loop() {
// put your main code here, to run repeatedly:
pressure1 = analogRead(FSR1);
pressure2 = analogRead(FSR2);
pressure3 = analogRead(FSR3);
mappedP1 = map(pressure1, 0, 1023, 0, 255);//change based on Sensor Reading
mappedP2 = map(pressure2, 0, 1023, 0, 255);
mappedP3 = map(pressure3, 0, 1023, 0, 255);
if(mappedP1 > 35){
score = score + 20; //time that sensor records hit is too long
hits = hits + 1;
delay(400);
}
if(mappedP2 > 0){
score = score + 5;
hits = hits+1;
delay(400);
}
//Green Lights
if (hits < 6){
for(int i = 0; i < hits; i++){
strip1.setPixelColor(i, 255, 0, 0);
strip1.show();
}
//Serial.print("Less Than 6");
}
if(hits > 6 && hits < 10){
//Serial.print("Greater Than 6 ");
for(int i = 0; i < 6; i++)
{
strip1.setPixelColor(i, 255, 0, 0);
strip1.show();
}
}
//Blue Lights
if (hits < 16 && hits >= 10){
for(int i = 0; i < hits-10; i++){
strip1.setPixelColor(i, 0, 0,255);
strip1.show();
}
}
if(hits > 16 && hits < 20){
for(int i = 0; i < 6; i++)
{
strip1.setPixelColor(i, 0, 0, 255);
strip1.show();
}
}
//Red Lights
if (hits < 26 && hits >= 20){
for(int i = 0; i < hits-20; i++){
strip1.setPixelColor(i, 0, 255, 0);
strip1.show();
}
}
if(hits > 26 && hits < 30){
for(int i = 0; i < 6; i++)
{
strip1.setPixelColor(i, 0, 255, 0);
strip1.show();
}
}
Serial.print("Score: ");
Serial.println(mappedP2);
sprintf(tempString, "%4d", score);
s7s.print(tempString);
}
void clearDisplay()
{
s7s.write(0x76); // Clear display command
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment