Created
May 31, 2018 00:19
-
-
Save arduinoboard/3bd28e0eff134aa724d2553632421873 to your computer and use it in GitHub Desktop.
The file that is currently on an Pro Trinket 5V/16MHz (FTDI) with a serial number of A603H96Q
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Adafruit_NeoPixel.h> | |
#ifdef __AVR__ | |
#include <avr/power.h> | |
#endif | |
#define LEDSTRIP 6 | |
#define NUMPIXELS 48 | |
#define BRIGHTNESS 255 | |
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, LEDSTRIP, NEO_GRBW + NEO_KHZ800); | |
bool touchingWheel = false; | |
bool ledEnable = true; | |
const int touchPin = 4; | |
int touchCount=0; | |
void setup() { | |
//For Trinket | |
#if defined (__AVR_ATtiny85__) | |
if (F_CPU == 16000000) | |
clock_prescale_set(clock_div_1); | |
#endif | |
pinMode(touchPin, INPUT); | |
Serial.begin(115200); | |
steeringWheelLightOff(); | |
pixels.setBrightness(BRIGHTNESS); | |
pixels.begin(); | |
pixels.show(); // Initialize all pixels to 'off' | |
} | |
void steeringWheelLightOff(){ | |
for(int i=0;i<NUMPIXELS;i++){ | |
pixels.setPixelColor(i, pixels.Color(0,0,0,0)); | |
} | |
pixels.show(); // This sends the updated pixel color to the hardware. | |
} | |
void loop() { | |
String serialString; | |
if (Serial.available() > 0) { | |
serialString = Serial.readStringUntil('\n'); | |
if (serialString=="who"){ | |
Serial.print("steering hub");//(driver, passenger, steering) | |
}else if(serialString.startsWith("bIBlue")){ | |
inBlue(); | |
}else if(serialString.startsWith("bOBlue")){ | |
outBlue(); | |
}else if(serialString.startsWith("bDisable")){ | |
ledEnable=false; | |
}else if(serialString.startsWith("bEnable")){ | |
ledEnable=true; | |
} | |
} | |
if(digitalRead(touchPin)==HIGH && touchCount<5){ | |
touchCount++; | |
}else if(digitalRead(touchPin)==LOW && touchCount>0){ | |
touchCount--; | |
} | |
if(touchCount == 5 && touchingWheel==false){ | |
touchingWheel=true; | |
outBlue(); | |
} | |
if(touchCount == 0 && touchingWheel==true){ | |
touchingWheel=false; | |
inBlue(); | |
} | |
} | |
void inBlue(){ | |
int width = 14; | |
for(int i=0;i<width;i++){ | |
turnPixelBlue(i,255); | |
} | |
pixels.show(); // This sends the updated pixel color to the hardware. | |
for(int i=width;i<NUMPIXELS-width;i++){ | |
turnPixelBlue(i,255); | |
pixels.show(); // This sends the updated pixel color to the hardware. | |
delay(10); | |
} | |
for(int i=NUMPIXELS-width;i<NUMPIXELS;i++){ | |
turnPixelBlue(i,255); | |
} | |
pixels.show(); // This sends the updated pixel color to the hardware. | |
} | |
void turnPixelBlue(int i, int brightness){ | |
if(i%2==0){ | |
pixels.setPixelColor((NUMPIXELS/2)+(i/2), pixels.Color(0,0,brightness,0)); | |
}else{ | |
pixels.setPixelColor((NUMPIXELS/2)-(i/2)-1, pixels.Color(0,0,brightness,0)); | |
} | |
} | |
void outBlue(){ | |
int width = 14; | |
for(int i=NUMPIXELS-width;i<NUMPIXELS;i++){ | |
turnPixelBlue(i,0); | |
} | |
pixels.show(); // This sends the updated pixel color to the hardware. | |
for(int i=NUMPIXELS-width-1;i>=width;i--){ | |
turnPixelBlue(i,0); | |
pixels.show(); // This sends the updated pixel color to the hardware. | |
delay(10); | |
} | |
for(int i=0;i<width;i++){ | |
turnPixelBlue(i,0); | |
} | |
pixels.show(); // This sends the updated pixel color to the hardware. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment