Created
September 7, 2022 12:38
-
-
Save DeviNoles/cd9e476d2e7b22c6690d97e61dcaca91 to your computer and use it in GitHub Desktop.
This file contains 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 <string.h> | |
#include <stdio.h> | |
#include <Adafruit_NeoPixel.h> | |
// Which pin on the Arduino is connected to the NeoPixels? | |
#define PIN 0 // On Trinket or Gemma, suggest changing this to 1 | |
// How many NeoPixels are attached to the Arduino? | |
#define NUMPIXELS 15 // Popular NeoPixel ring size | |
// When setting up the NeoPixel library, we tell it how many pixels, | |
// and which pin to use to send signals. Note that for older NeoPixel | |
// strips you might need to change the third parameter -- see the | |
// strandtest example for more information on possible values. | |
// software serial #1: RX = digital pin 10, TX = digital pin 11 | |
// software serial #2: RX = digital pin 8, TX = digital pin 9 | |
// on the Mega, use other pins instead, since 8 and 9 don't work on the Mega | |
#if defined(__SAM3X8E__) | |
#undef __FlashStringHelper::F(string_literal) | |
#define F(string_literal) string_literal | |
#endif | |
const unsigned int MAX_INPUT = 50; | |
String prevGear; | |
// When using the BREAKOUT BOARD only, use these 8 data lines to the LCD: | |
// For the Arduino Uno, Duemilanove, Diecimila, etc.: | |
// D0 connects to digital pin 8 (Notice these are | |
// D1 connects to digital pin 9 NOT in order!) | |
// D2 connects to digital pin 2 | |
// D3 connects to digital pin 3 | |
// D4 connects to digital pin 4 | |
// D5 connects to digital pin 5 | |
// D6 connects to digital pin 6 | |
// D7 connects to digital pin 7 | |
// For the Arduino Mega, use digital pins 22 through 29 | |
// (on the 2-row header at the end of the board). | |
// D0 connects to digital pin 22 | |
// D1 connects to digital pin 23 | |
// D2 connects to digital pin 24 | |
// D3 connects to digital pin 25 | |
// D4 connects to digital pin 26 | |
// D5 connects to digital pin 27 | |
// D6 connects to digital pin 28 | |
// D7 connects to digital pin 29 | |
// For the Arduino Due, use digital pins 33 through 40 | |
// (on the 2-row header at the end of the board). | |
// D0 connects to digital pin 33 | |
// D1 connects to digital pin 34 | |
// D2 connects to digital pin 35 | |
// D3 connects to digital pin 36 | |
// D4 connects to digital pin 37 | |
// D5 connects to digital pin 38 | |
// D6 connects to digital pin 39 | |
// D7 connects to digital pin 40 | |
#define YP A2 // must be an analog pin, use "An" notation! | |
#define XM A3 // must be an analog pin, use "An" notation! | |
#define YM 8 // can be a digital pin | |
#define XP 9 // can be a digital pin | |
// Assign human-readable names to some common 16-bit color values: | |
#define BLACK 0x0000 | |
#define BLUE 0x001F | |
#define RED 0xF800 | |
#define GREEN 0x07E0 | |
#define CYAN 0x07FF | |
#define MAGENTA 0xF81F | |
#define YELLOW 0xFFE0 | |
#define WHITE 0xFFFF | |
float lastRL=6750, lastR; | |
//NEOPIXEL DEFINITIONS | |
#define DELAYVAL 3000 | |
//DEBUG MODE 0 IS OFF 1 IS ON | |
#define DEV_MODE 1 | |
#define REV_MODE 0 | |
int oldcolor, currentcolor; | |
Adafruit_NeoPixel pixels(NUMPIXELS, 0, NEO_GRB + NEO_KHZ800); | |
void setup(void) { | |
Serial.begin(115200); | |
while (!Serial) { | |
; // wait for serial port to connect. Needed for native USB port only | |
} | |
// tft.fillRect(0, 0, BOXSIZE, BOXSIZE, RED); | |
// tft.drawRect(0, 0, BOXSIZE, BOXSIZE, WHITE); | |
// pinMode(13, OUTPUT); | |
pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED) | |
pixels.clear(); // Set all pixel colors to 'off' | |
pixels.setBrightness(50); | |
// The first NeoPixel in a strand is #0, second is 1, all the way up | |
// to the count of pixels minus one. | |
fillNeoPixel(pixels.Color(255,0,0), 0); | |
delay(1000); | |
pixels.clear(); // Set all pixel colors to 'off' | |
pixels.show(); | |
} | |
// Example 2 - Receive with an end-marker | |
const byte numChars = 32; | |
char receivedChars[numChars]; // an array to store the received data | |
boolean newData = false; | |
void loop() { | |
// Serial.print("HERE"); | |
parseBuffer(); | |
} | |
void showNewData() { | |
if (newData == true) { | |
// Serial.println(receivedChars); | |
parseInputData(); | |
newData = false; | |
} | |
} | |
void parseBuffer(){ | |
recvWithEndMarker(); | |
showNewData(); | |
} | |
void setNeoPixel( uint32_t pixColor, uint32_t pixid ) { | |
// pixels.clear(); // Set all pixel colors to 'off' | |
// The first NeoPixel in a strand is #0, second is 1, all the way up | |
// to the count of pixels minus one. | |
// pixels.Color() takes RGB values, from 0,0,0 up to 255,255,255 | |
// Here we're using a moderately bright green color: | |
pixels.setPixelColor(pixid, pixColor); | |
// // Send the updated pixel colors to the hardware. | |
} | |
void fillNeoPixel( uint32_t pixColor, uint16_t firstPix ){ | |
// The first NeoPixel in a strand is #0, second is 1, all the way up | |
// to the count of pixels minus one. | |
// pixels.Color() takes RGB values, from 0,0,0 up to 255,255,255 | |
// Here we're using a moderately bright green color: | |
pixels.fill(pixColor, firstPix); | |
pixels.show(); // Send the updated pixel colors to the hardware. | |
} | |
void flashRedLikeCrazy(){ | |
fillNeoPixel(pixels.Color(255,0,0), 0); | |
} | |
void updateRevBar(uint32_t pixColor, int upTyp){ | |
if(REV_MODE==0){ | |
float ePix2 = (((float) lastR/ (float) lastRL) * 9); | |
pixels.clear(); | |
if((int)ePix2==8){ | |
pixels.show(); | |
delay(50); | |
flashRedLikeCrazy(); | |
return; | |
} | |
for(int i=0; i<(int)ePix2;i++){ | |
if(i<4){ | |
setNeoPixel(pixels.Color(0,0,255), i); | |
setNeoPixel(pixels.Color(0,0,255), NUMPIXELS-i-1); | |
} | |
else if(i==8){ | |
} | |
else if(i>=4){ | |
setNeoPixel(pixels.Color(0,255,0), i); | |
setNeoPixel(pixels.Color(0,255,0), NUMPIXELS-i-1); | |
} | |
} | |
pixels.show(); | |
} | |
else if(REV_MODE==1){ | |
} | |
} | |
void recvWithEndMarker() { | |
static byte ndx = 0; | |
char endMarker = '\n'; | |
char rc; | |
while (Serial.available() > 0 && newData == false) { | |
rc = Serial.read(); | |
if (rc != endMarker) { | |
receivedChars[ndx] = rc; | |
ndx++; | |
if (ndx >= numChars) { | |
ndx = numChars - 1; | |
} | |
} | |
else { | |
receivedChars[ndx] = '\0'; // terminate the string | |
ndx = 0; | |
newData = true; | |
} | |
} | |
} | |
void writeBufferObject(char *valBufObj){ | |
Serial.println(valBufObj); | |
// tft.setTextSize(tSize); | |
// tft.setCursor(xpos, ypos); | |
// tft.print(valBufObj); | |
}//// | |
void parseInputData(){ | |
char *cutRChar = receivedChars + 1; | |
char *val1 = strtok(cutRChar,","); | |
char *val2 = strtok(NULL, ">"); | |
// Serial.println(val1); | |
// Serial.println(val2); | |
if(strcmp(val1, "RL") == 0){ | |
lastRL = atoi(val2); | |
Serial.println(lastRL); | |
updateRevBar(pixels.Color(0,0,255),0); | |
} | |
else if(strcmp(val1, "R") == 0){ | |
Serial.print("val2 IS: "); | |
Serial.println(val2); | |
lastR = atoi(val2); | |
Serial.println(lastR); | |
updateRevBar(pixels.Color(0,0,255),1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment