Skip to content

Instantly share code, notes, and snippets.

@frap129
Created March 21, 2018 14:50
Show Gist options
  • Save frap129/11638172a9912e457f1344ad4af8220a to your computer and use it in GitHub Desktop.
Save frap129/11638172a9912e457f1344ad4af8220a to your computer and use it in GitHub Desktop.
//CSK 3/17/2013 Libraries new location
//https://github.com/FastLED/FastLED
//https://github.com/FastLED/FastLED/wiki/Overview
#include "FastLED.h"
// Constants
#define COLOR_ORDER GRB
#define MAX_BRIGHTNESS 200 // MAX is actually 255, set to 200 to reduce draw and thermal output
#define NUM_LEDS 150
#define DATA_PIN 6 // White wire from the http://www.andymark.com/product-p/am-2917.htm power connector
// Class variables
CRGB leds[NUM_LEDS]; // Array of LEDs
int shootPin = 7; // Input from RIO to tell if we're shooting or not
int shootVal = 0;
int switchPin = 8; // Input from RIO to tell if were dropping or not
int switchVal = 0;
int alliancePin = 8; // Input from RIO to tell what alliance we are
int allianceVal = 0;
CRGB allianceColor = CRGB::Green; // The alliance color, default green
int scaleIterations = 1;
void setup()
{
// Register input pins
pinMode(shootPin, INPUT);
pinMode(switchPin, INPUT);
pinMode(alliancePin, INPUT);
// Register LED strip, start solid green
FastLED.addLeds<WS2812B, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.clear();
FastLED.setBrightness(MAX_BRIGHTNESS);
fill_solid(leds, NUM_LEDS, allianceColor);
FastLED.show();
// Start serial port at 9600 bps
Serial.begin(9600);
}
void loop()
{
// Collect pin values
shootVal = digitalRead(shootPin);
switchVal = digitalRead(switchPin);
allianceVal = digitalRead(alliancePin);
// Set alliance color
if (allianceVal == HIGH)
allianceColor = CRGB::Red;
else
allianceColor = CRGB::Blue;
if (shootVal = HIGH)
shootAnim();
else if (switchVal == HIGH)
switchAnim();
else {
fill_solid(leds, NUM_LEDS, allianceColor);
scaleIterations = 1;
}
}
void shootAnim()
{
// Calculate delay time in microseconds
int wait = 3000
if (1 < scaleIterations && scaleIterations < 5)
wait = wait / scaleIterations;
// Start animation
FastLED.setBrightness(MAX_BRIGHTNESS);
for(int led_number = 0; led_number < NUM_LEDS; led_number++)
{
// Turn on LED
leds[led_number] = allianceColor;
FastLED.show();
// Pause before "going" to next LED
delayMicroseconds(wait);
}
for(int led_number = 0; led_number < NUM_LEDS; led_number++)
{
// Turn off LED
leds[led_number] = CRGB::Black;
FastLED.show();
// Pause before "going" to next LED
delayMicroseconds(wait);
}
// Increment iterations
scaleIterations = scaleIterations++;
}
void switchAnim()
{
int wait = 4;
FastLED.setBrightness(MAX_BRIGHTNESS);
for(int led_number = 0; led_number < NUM_LEDS; led_number++)
{
// Turn on LED
leds[led_number] = allianceColor;
FastLED.show();
// Pause before "going" to next LED
delay(wait);
}
for(int led_number = 0; led_number < NUM_LEDS; led_number++)
{
// Turn off LED
leds[led_number] =CRGB::Black;
FastLED.show();
// Pause before "going" to next LED
delay(wait);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment