Last active
December 12, 2020 11:04
-
-
Save Nekodigi/ef1ef0dbfd58539acafecbc2c1ccb7ca 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 <Adafruit_NeoPixel.h> | |
#define PIN 2 | |
#define NUMPIXELS 300 | |
#define DELAY 10 | |
const float briLen = 150;//length of lightning area | |
const float hueLen = 150;//length of hue cycle | |
float bri = 50;//=brightness/2 | |
const float briSpeed = 1;//brightness transition speed | |
const float hueSpeed = 1.1;//hue transition speed | |
boolean power = true; | |
float briChange = 0;//brightness factor | |
float hueChange = 0;//hue factor | |
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); | |
void setup() { | |
pixels.begin(); | |
Serial.begin(9600); | |
} | |
void serialEvent(){ | |
if(Serial.available() > 1){ | |
char flag = Serial.read(); | |
if(flag == 'p'){ | |
if(Serial.read() == 'o')power = true; | |
else power = false; | |
Serial.println("pxOK\n"); | |
} | |
if(flag == 'b'){ | |
Serial.println("bxOK\n"); | |
bri = Serial.read(); | |
Serial.println(bri); | |
} | |
} | |
} | |
void loop() { | |
pixels.clear(); | |
if(power){ | |
for(int i=0; i<NUMPIXELS/2; i++){ | |
float hueFac = 65536*(i+hueChange)/hueLen; | |
float briFac = TWO_PI*(i+briChange)/briLen; | |
if(0 < briFac && briFac < TWO_PI){ | |
pixels.setPixelColor(i, pixels.ColorHSV(hueFac, 255, (1.0 - cos(briFac))*bri));//~65536?, ~256, ~256 | |
pixels.setPixelColor(NUMPIXELS-i, pixels.ColorHSV(hueFac, 255, (1.0 - cos(briFac))*bri));//~65536?, ~256, ~256 | |
} | |
} | |
//pixels.setPixelColor(frameCount%NUMPIXELS, pixels.ColorHSV(((frameCount)*500), 255, 5));//~65536?, ~256, ~256 | |
//pixels.setPixelColor((NUMPIXELS-frameCount)%NUMPIXELS, pixels.ColorHSV(((frameCount)*500), 255, 5));//~65536?, ~256, ~256 | |
pixels.show(); | |
delay(DELAY); | |
//update factor | |
briChange += briSpeed; | |
if(briChange > briLen){ | |
briChange = -NUMPIXELS/2; | |
} | |
hueChange += hueSpeed; | |
// if(hueChange > hueLen){ | |
// hueChange = -NUMPIXELS/2; | |
// } | |
} | |
pixels.show(); | |
} |
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
import processing.serial.*; | |
import processing.sound.*; | |
AudioIn in; | |
Amplitude amp; | |
// The serial port: | |
Serial myPort; | |
void setup(){ | |
size(1000, 500); | |
amp = new Amplitude(this); | |
in = new AudioIn(this, 0); | |
in.start(); | |
amp.input(in); | |
in.start(); | |
// List all the available serial ports: | |
printArray(Serial.list()); | |
// Open the port you are using at the rate you want: | |
myPort = new Serial(this, "COM6", 9600); | |
delay(1000); | |
//myPort.write("aaaa"); | |
// Send a capital A out the serial port: | |
//myPort.write("b1pp"); | |
//while(myPort.available() < 0); | |
//println(myPort.readStringUntil('\n')); | |
//println(myPort.readStringUntil('\n')); | |
//myPort.write(1); | |
myPort.write("aa");//initialize | |
//for(int i=0; i<2; i++){ | |
//} | |
//myPort.write("p"); | |
frameRate(10); | |
} | |
void mousePressed(){ | |
if(mouseButton == LEFT){ | |
myPort.write("po");//power on | |
}else{ | |
myPort.write("pf");//power off | |
} | |
} | |
void draw(){ | |
//if(myPort.available() > 0) | |
//println(myPort.readStringUntil('\n')); | |
myPort.write("b"); | |
//println(amp.analyze()*12700); | |
myPort.write(int(amp.analyze()*12700)); | |
//myPort.write(constrain(int(map(mouseX, 0, width, 0, 127)), 0, 127)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment