Skip to content

Instantly share code, notes, and snippets.

@kfrank
Created November 12, 2018 06:43
Show Gist options
  • Save kfrank/f8e9117e7f4eb3110a9bb6a105da22f5 to your computer and use it in GitHub Desktop.
Save kfrank/f8e9117e7f4eb3110a9bb6a105da22f5 to your computer and use it in GitHub Desktop.
status board for pushing and pulling code
#include <Button.h> // From our class
#define TOLERANCE 10 // For the potentiometer
// include LED library code
#include <FastLED.h> // Fast LED library
#define NUM_LEDS 60
#define DATA_PIN 3
CRGB leds[NUM_LEDS];
// include LCD library code
#include "Wire.h"
#include "Adafruit_LiquidCrystal.h"
Adafruit_LiquidCrystal lcd(0);
//
// VARS
//
// LED color
int interval = 1000;
int startColorHue = 280; int endColorHue = 180; int colorHue;
int startColorValue = 200; int endColorValue = 100; int colorValue;
int statusLeds[] = {3, 4, 6, 8, 9};
// LCD Button pins
int buttonUp = 4;
int buttonDown = 5;
// LCD Branch Selection Vars and Setup
String branchNames[] = {"design/headersidebar", "design/challenges", "dev/npm", "kf/home_news"};
int branchPos = 0;
int softRead = 0;
// Push pull
int potInit = 0;
boolean push = false;
boolean pull = false;
//
// TESTING
//
// Simulate coworker commits
const int btn1Pin = 12;
const int btn2Pin = 11;
Button butt1 (btn1Pin);
Button butt2 (btn2Pin);
int butVal;
//
// LOOPS
//
// LED Turn off
void ledOff() {
for(int led; led < NUM_LEDS; led++) {
leds[led] = CRGB::Black;
FastLED.show();
}
}
// LED Fade from green to purple
void ledFade() {
int action1 = butt1.checkButtonAction();
int action2 = butt2.checkButtonAction();
if ( digitalRead(12) == HIGH ) {
butVal = 0;
for (float i = 0; i < interval; i++){
colorHue = startColorHue - (((i+1) / interval) * (startColorHue - endColorHue));
colorValue = startColorValue - (((i+1) / interval) * (startColorValue - endColorValue));
leds[5] = CHSV(colorHue, 255, colorValue);
FastLED.show();
}
}
if ( digitalRead(11) == HIGH ) {
for (float i = 0; i < interval; i++){
colorHue = startColorHue - (((i+1) / interval) * (startColorHue - endColorHue));
colorValue = startColorValue - (((i+1) / interval) * (startColorValue - endColorValue));
leds[7] = CHSV(colorHue, 255, colorValue);
FastLED.show();
}
}
}
// LCD Branch Selection
void branchSelect() {
if (digitalRead(buttonUp) == LOW) {
Serial.println("up clicked");
delay(500);
if (branchPos != 0) {
branchPos = branchPos - 1;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(branchNames[branchPos]);
}
ledOff();
}
if (digitalRead(buttonDown) == LOW) {
Serial.println("down clicked");
delay(500);
if (branchPos < 3) {
branchPos = branchPos + 1;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(branchNames[branchPos]);
}
ledOff();
}
}
// Push Pull
void pushPull() {
int potRead = analogRead(A3);
potRead = map(potRead, 0, 1023, 0, 179);
int change = abs(potRead - potInit);
if (change > TOLERANCE) {
if (potRead > 150) {
if (potInit < potRead) {
Serial.println("Pull");
// LED pull sequence
for(int i = 0; i < 5; i++) {
leds[statusLeds[i]] = CHSV(193, 255, 50);
FastLED.show();
delay(500 - (i * 100));
}
for(int i = 0; i < 5; i++) {
leds[statusLeds[i]] = CRGB::Black;
}
FastLED.show();
delay(500);
for(int i = 0; i < 5; i++) {
leds[statusLeds[i]] = CHSV(193, 255, 50);
}
FastLED.show();
delay(500);
for(int i = 0; i < 5; i++) {
leds[statusLeds[i]] = CRGB::Black;
}
FastLED.show();
delay(500);
leds[9] = CHSV(280, 255, 50);
FastLED.show();
// turn off coworker lights after pull
leds[5] = CRGB::Black;
leds[7] = CRGB::Black;
FastLED.show();
pull = true;
} else {
ledOff();
pull = false;
}
potInit = potRead;
}
if (potRead < 25) {
if (potInit > potRead) {
Serial.println("Push");
// LED pull sequence
for(int i = 4; i >= 0; i--) {
leds[statusLeds[i]] = CHSV(193, 255, 50);
FastLED.show();
delay(500 - (i * 100));
}
for(int i = 4; i >= 0; i--) {
leds[statusLeds[i]] = CRGB::Black;
}
FastLED.show();
delay(500);
for(int i = 4; i >= 0; i--) {
leds[statusLeds[i]] = CHSV(193, 255, 50);
}
FastLED.show();
delay(500);
for(int i = 4; i >= 0; i--) {
leds[statusLeds[i]] = CRGB::Black;
}
FastLED.show();
delay(500);
leds[3] = CHSV(280, 255, 50);
FastLED.show();
// turn off coworker lights after pull
leds[5] = CRGB::Black;
leds[7] = CRGB::Black;
FastLED.show();
push = true;
} else {
ledOff();
push = false;
}
potInit = potRead;
}
}
}
//
// ARDUINO
//
void setup() {
Serial.begin(9600);
// test buttons
pinMode(12, INPUT);
pinMode(11, INPUT);
// potentiometer
pinMode(A3, INPUT);
// LCD number of rows and columns setup:
lcd.begin(16, 2);
lcd.print(branchNames[branchPos]);
// LCD Button setup
pinMode(buttonUp, INPUT_PULLUP);
pinMode(buttonDown, INPUT_PULLUP);
// LED put your setup code here, to run once:
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
ledOff();
}
void loop() {
branchSelect();
ledFade();
pushPull();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment