Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "FastLED.h"
- #define NUM_LEDS 60 // how many leds in our strip
- #define DATA_PIN 6 // neopixel data pin
- #define POT_PIN A0 // center pin of pot
- #define buttonPin 5 // push me
- int buttonState = 0; // was i pushed
- //int palette[]={176,113,109,132};
- int palette[]={252,160}; //police red blue
- int paletteCt = (sizeof(palette) / sizeof(palette[0])); // how big is our palette
- int sintemp = random(250); // random seeds for various wave generators
- int costemp = random(250);
- int tritemp = random(250);
- int cubictemp = random(250);
- int quadtemp = random(250);
- int sintemp1 = random(250);
- int sintemp2 = random(250);
- int sintemp3 = random(250);
- int accel1 = 0; // how much do we add to car 1's progress
- int accel2 = 0; // and dont forget car 2
- int tail = 15; // threshhold for our heroes to slow their approach
- CRGB leds[NUM_LEDS]; // Define the array of leds
- void setup() {
- FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS); // are there any donuts? I'm starving
- FastLED.clear();
- FastLED.show();
- Serial.begin(9600);
- pinMode(buttonPin, INPUT);
- pinMode(A0, INPUT);
- randomSeed(analogRead(A0));
- Serial.println(random(256));
- }
- void loop() {
- int getaway = random(0,3); // how fast is our getaway
- buttonState = digitalRead(buttonPin); // read the button
- if(buttonState==HIGH){
- sintemp1 = random(250); //reset random seeds
- sintemp2 = random(250);
- sintemp3 = random(250);
- Serial.println("i was pushed");
- }
- //if(buttonState==HIGH) palette[paletteCt-2] = potmap();
- //palette[paletteCt-1] = potmap();
- if (sintemp1 - sintemp3 < tail) accel1 = random(0,2); // [cop1] we are getting close slow down
- if (sintemp1 - sintemp3 > tail) accel1 = random(0,3); //[cop1] were did he go?
- if (sintemp2 - sintemp3 < tail) accel2 = random(0,2);// [cop2] we are getting close slow down
- if (sintemp2 - sintemp3 > tail) accel2 = random(0,3);// [cop2] Again?
- if(sintemp1 == (sintemp3 -4)) accel1 = random(0,1); // [cop1] I'm in position
- if(sintemp2 == (sintemp3 -8)) accel2 = random(0,1);// [cop2] I'm in position
- if(sintemp1 == sintemp2) sintemp3 += getaway; // I got him first
- sintemp1 += accel1; // how much faster should I go?
- sintemp2 += accel2; // as fast as your heart will take you
- int cop1 = map(fastsin1(),0,254,0,NUM_LEDS-1); // what the hell does this guy think he is doing?
- int cop2 = map(fastsin2(),0,254,0,NUM_LEDS-1); // none shall pass!
- int car3 = map(fastsin3(),0,254,0,NUM_LEDS-1); // oh yeah, swipe right!
- leds[cop1]=CHSV(palette[random(paletteCt)],255,random(10,120)); // Officer John Baker
- leds[cop2]=CHSV(palette[random(paletteCt)],255,random(10,120)); // Officer Frank Poncherello
- //leds[car3]=CHSV(palette[random(paletteCt)],128,random(80,100)); // Officer Farva
- //leds[car3]=CHSV(random(255),255,random(80,100)); // Pussy Wagon
- leds[car3]=CHSV(0,0,random(80,100)); // average everyday citizen
- //Serial.print(palette[0]);
- //Serial.print(" ");
- //Serial.println(palette[1]);
- FastLED.show();
- FastLED.clear();
- delay(10);
- }
- // Here Be Dragons //
- int fastsin1(){
- int exportvar = sin8(sintemp1);
- sintemp1++;
- if (sintemp1 >= 255) sintemp1 = 0;
- return exportvar;
- }
- int fastsin2(){
- int exportvar = sin8(sintemp2);
- sintemp2++;
- if (sintemp2 >= 255) sintemp2 = 0;
- return exportvar;
- }
- int fastsin3(){
- int exportvar = sin8(sintemp3);
- sintemp3++;
- if (sintemp3 >= 255) sintemp3 = 0;
- return exportvar;
- }
- int fastsin(){
- int exportvar = sin8(sintemp);
- sintemp++;
- if (sintemp >= 255) sintemp = 0;
- return exportvar;
- }
- int fasttri(){
- int exportvar = triwave8(tritemp);
- tritemp++;
- if (tritemp >= 255) tritemp = 0;
- return exportvar;
- }
- int fastquad(){
- int exportvar = quadwave8(quadtemp);
- quadtemp++;
- if (quadtemp >= 255) quadtemp = 0;
- return exportvar;
- }
- int fastcubic(){
- int exportvar = cubicwave8(cubictemp);
- cubictemp++;
- if (cubictemp >= 255) cubictemp = 0;
- return exportvar;
- }
- int fastcosin(){
- int exportvar = cos8(costemp);
- costemp++;
- if (costemp >= 255) costemp = 0;
- return exportvar;
- }
- int potmap(){ // map analog sensor 0-255
- int sensorValue = analogRead(POT_PIN);
- sensorValue = map(sensorValue,0,1023,0,255);
- return sensorValue;
- }
- int npotmap(){ // map analog sensor 255-0
- int sensorValue = analogRead(POT_PIN);
- sensorValue = map(sensorValue,0,1023,255,0);
- return sensorValue;
- }
- unsigned int potmap2(unsigned int range){ // map analog sensor 0- custom value
- unsigned int sensorValue = analogRead(POT_PIN);
- sensorValue = map(sensorValue,0,1023,0,range);
- return sensorValue;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement