Skip to content

Instantly share code, notes, and snippets.

@caitlinsdad
Created April 2, 2018 19:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caitlinsdad/482317ee3c07244d419690206583355d to your computer and use it in GitHub Desktop.
Save caitlinsdad/482317ee3c07244d419690206583355d to your computer and use it in GitHub Desktop.
#include <Wire.h>
#include <SPI.h>
#include <LiquidCrystal_I2C.h>
#include <Adafruit_NeoPixel.h>
#include <Adafruit_CircuitPlayground.h>
#define BACKLIGHT_PIN (3)
#define LED_ADDR (0x27) // might need to be 0x3F, if 0x27 doesn't work
LiquidCrystal_I2C lcd(LED_ADDR, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE) ;
// Creat a set of new characters
const uint8_t charBitmap[][8] = {
{ 0xc, 0x12, 0x12, 0xc, 0, 0, 0, 0 },
{ 0x6, 0x9, 0x9, 0x6, 0, 0, 0, 0 },
{ 0x0, 0x6, 0x9, 0x9, 0x6, 0, 0, 0x0 },
{ 0x0, 0xc, 0x12, 0x12, 0xc, 0, 0, 0x0 },
{ 0x0, 0x0, 0xc, 0x12, 0x12, 0xc, 0, 0x0 },
{ 0x0, 0x0, 0x6, 0x9, 0x9, 0x6, 0, 0x0 },
{ 0x0, 0x0, 0x0, 0x6, 0x9, 0x9, 0x6, 0x0 },
{ 0x0, 0x0, 0x0, 0xc, 0x12, 0x12, 0xc, 0x0 }
};
#define CAP_THRESHOLD 50
#define DEBOUNCE 250
////////////////////////////////////////////////////////////////////////////
boolean capButton(uint8_t pad) {
if (CircuitPlayground.readCap(pad) > CAP_THRESHOLD) {
return true;
} else {
return false;
}
}
////////////////////////////////////////////////////////////////////////////
#define zzz 500
#define zzzz 3000
#define neobright 40
#define PIN 6
#define ANALOG_INPUT A0 // Specify the analog input to read.
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(29, PIN, NEO_GRB + NEO_KHZ800);
// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel. Avoid connecting
// on a live circuit...if you must, connect GND first.
bool oldState = HIGH;
int showType = 0;
void setup() {
CircuitPlayground.begin();
strip.begin();
strip.setBrightness(neobright);
strip.show(); // Initialize all pixels to 'off'
int charBitmapSize = (sizeof(charBitmap ) / sizeof (charBitmap[0]));
// Switch on the backlight
pinMode ( BACKLIGHT_PIN, OUTPUT );
digitalWrite ( BACKLIGHT_PIN, HIGH );
lcd.begin(20,4); // initialize the lcd
for ( int i = 0; i < charBitmapSize; i++ )
{
lcd.createChar ( i, (uint8_t *)charBitmap[i] );
}
}
void loop(){
// Get current button state.
bool newState = capButton(12);
// Check if state changed from high to low (button press).
if (newState == LOW && oldState == HIGH) {
// Short delay to debounce button.
delay(20);
// Check if button is still low after debounce.
newState = capButton(12);
if (newState == LOW) {
showType++;
if (showType > 5)
showType=0;
// lcd.clear();
// lcd.home();
// lcd.print(showType);
// delay(300);
startShow(showType);
}
}
// Set the last button state to the old state.
oldState = newState;
}
void startShow(int i) {
switch(i){
case 0: theaterChase(strip.Color(0, 255, 100), 50); // teal
break;
case 1: theaterChase(strip.Color(255, 0, 255), 50); // purple
break;
case 2: rainbow(20);
break;
case 3: rainbowCycle(20);
break;
case 4: theaterChaseRainbow(50);
break;
case 5: theaterChase2(strip.Color(255, 0, 0), 50); // red
break;
}
}
// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}
void rainbow(uint8_t wait) {
uint16_t i, j, k;
//-------------------------------------------------
lcd.clear();
lcd.home (); // go home
lcd.print("*** IT'S THE WAY ***");
delay ( zzz );
lcd.setCursor ( 20, 0 ); // go to the next line
lcd.print(" WE ROLL...");
delay ( zzz );
lcd.setCursor ( 20, 1 );
roller();
CircuitPlayground.playTone(790, 800);
//-------------------------------------------------
for(j=0; k<3; k++) {
for(j=0; j<256; j++) {
for(i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel((i+j) & 255));
}
strip.show();
delay(wait);
}
}
colorWipe(strip.Color(255, 255, 255), 50);
}
// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
uint16_t i, j;
//-------------------------------------------------
lcd.clear();
lcd.home (); // go home
lcd.print(" ** ON A SEA- **");
delay ( zzz );
lcd.setCursor ( 0, 1 );
lcd.print(" FOOD DIET?");
delay ( zzz );
lcd.setCursor ( 20, 0 ); // go to the next line
lcd.print(" SEE FOOD,");
delay ( zzz );
lcd.setCursor ( 20, 1 );
lcd.print(" EAT IT!");
CircuitPlayground.playTone(620, 200);
CircuitPlayground.playTone(530, 600);
//-------------------------------------------------
for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
for(i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
}
strip.show();
delay(wait);
}
colorWipe(strip.Color(255, 255, 255), 50);
}
//Theatre-style crawling lights.
void theaterChase(uint32_t c, uint8_t wait) {
//-------------------------------------------------
lcd.clear();
lcd.home (); // go home
lcd.print(" *** TRY THE ***");
delay ( zzz );
lcd.setCursor ( 0, 1 );
lcd.print(" BEST,");
delay ( zzz );
lcd.setCursor ( 20, 0 ); // go to the next line
lcd.print(" FUGU THE");
delay ( zzz );
lcd.setCursor ( 20, 1 );
lcd.print(" REST!");
CircuitPlayground.playTone(500, 200);
CircuitPlayground.playTone(600, 300);
CircuitPlayground.playTone(500, 500);
//-------------------------------------------------
for (int j=0; j<10; j++) { //do 10 cycles of chasing
for (int q=0; q < 3; q++) {
for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, c); //turn every third pixel on
}
strip.show();
delay(wait);
for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, 0); //turn every third pixel off
}
}
}
colorWipe(strip.Color(255, 0, 255), 50);
colorWipe(strip.Color(255, 255, 255), 50);
}
//Theatre-style crawling lights.
void theaterChase2(uint32_t c, uint8_t wait) {
//-------------------------------------------------
lcd.clear();
lcd.home (); // go home
lcd.print("**** CASH ONLY! ****");
delay ( zzz );
lcd.setCursor ( 0, 1 );
lcd.print(" TIPS");
delay ( zzz );
lcd.setCursor ( 20, 0 ); // go to the next line
lcd.print(" ARE");
delay ( zzz );
lcd.setCursor ( 20, 1 );
lcd.print(" APPRECIATED! :)");
CircuitPlayground.playTone(600, 200);
delay(100);
CircuitPlayground.playTone(400, 600);
delay(200);
CircuitPlayground.playTone(400, 600);
delay(100);
CircuitPlayground.playTone(400, 400);
delay(100);
CircuitPlayground.playTone(400, 900);
//-------------------------------------------------
for (int j=0; j<10; j++) { //do 10 cycles of chasing
for (int q=0; q < 3; q++) {
for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, c); //turn every third pixel on
}
strip.show();
delay(wait);
for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, 0); //turn every third pixel off
}
}
}
colorWipe(strip.Color(255, 0, 0), 0);
delay(300);
colorWipe(strip.Color(0, 0, 0), 0);
delay(300);
colorWipe(strip.Color(255, 0, 0), 0);
delay(300);
colorWipe(strip.Color(0, 0, 0), 0);
delay(300);
colorWipe(strip.Color(255, 0, 0), 0);
delay(300);
colorWipe(strip.Color(0, 0, 0), 0);
delay(300);
colorWipe(strip.Color(255, 0, 0), 0);
delay(400);
colorWipe(strip.Color(255, 255, 255), 10);
}
//Theatre-style crawling lights with rainbow effect
void theaterChaseRainbow(uint8_t wait) {
//-------------------------------------------------
lcd.clear();
lcd.home (); // go home
lcd.print("*** NO MERCURY ***");
delay ( zzz );
lcd.setCursor ( 0, 1 );
lcd.print(" The current");
delay ( zzz );
lcd.setCursor ( 20, 0 ); // go to the next line
lcd.print(" temperature is:");
delay ( zzz );
lcd.setCursor ( 27, 1 );
//uint16_t value = analogRead(ANALOG_INPUT);
uint16_t value = CircuitPlayground.temperatureF();
lcd.print(value, DEC);
lcd.print(" o F");
CircuitPlayground.playTone(700, 80);
delay(100);
CircuitPlayground.playTone(700, 80);
delay(100);
CircuitPlayground.playTone(700, 80);
//-------------------------------------------------
for (int j=0; j < 256; j++) { // cycle all 256 colors in the wheel
for (int q=0; q < 3; q++) {
for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, Wheel( (i+j) % 255)); //turn every third pixel on
}
strip.show();
delay(wait);
for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, 0); //turn every third pixel off
}
}
}
colorWipe(strip.Color(255, 255, 255), 50);
}
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if(WheelPos < 85) {
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
void roller()
{
for ( int l = 0; l < 8; l++ ){
lcd.setCursor ( 0, 1 );
// Do a little animation by writing to the same location
for ( int i = 0; i < 2; i++ )
{
for ( int j = 0; j < 40; j++ )
{
lcd.print (char(random(7)));
}
lcd.setCursor ( 0, 1 );
// delay (15);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment