FinalProject: Kanpaku Party
Result
slide
movie
final Project Movie
code
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 6
#define NUMPIXELS 88
int limit = 80; //LED点灯の閾値。
//FFT
#define LIN_OUT 1 // 出力をリニアにする。
#define FFT_N 256 // set to 256 point fft
#include <FFT.h> // include the library
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int delayval = 500; // delay for half a second
void setup() {
Serial.begin(57600);
pixels.begin(); // This initializes the NeoPixel library.
TIMSK0 = 0; // turn off timer0 for lower jitter
ADCSRA = 0xe5; // set the adc to free running mode
ADMUX = 0x40; // use adc0
DIDR0 = 0x01; // turn off the digital input for adc0
}
void loop() {
while(1) { // reduces jitter
Serial.println(fft_lin_out[1]);
cli(); // UDRE interrupt slows this way down on arduino1.0
for (int i = 0 ; i < 512 ; i += 2) { // save 256 samples
while(!(ADCSRA & 0x10)); // wait for adc to be ready
ADCSRA = 0xf5; // restart adc
byte m = ADCL; // fetch adc data
byte j = ADCH;
int k = (j << 8) | m; // form into an int
k -= 0x0200; // form into a signed int
k <<= 6; // form into a 16b signed int
fft_input[i] = k; // put real data into even bins
fft_input[i+1] = 0; // set odd bins to 0
}
fft_window(); // window the data for better frequency response
fft_reorder(); // reorder the data before doing the fft
fft_run(); // process the data in the fft
fft_mag_lin(); // take the output of the fft リニアで値をとる。
sei();
//led
//01
if(fft_lin_out[9] > limit){
ch1_on();
}else {
ch1_off();
}
//02
if(fft_lin_out[8] > limit){
ch2_on();
}else {
ch2_off();
}
//03
if(fft_lin_out[7] > limit){
ch3_on();
} else {
ch3_off();
}
//04
if(fft_lin_out[6] > limit){
ch4_on();
} else {
ch4_off();
}
//05
if(fft_lin_out[1] > limit ){
ch5_on();
}else {
ch5_off();
}
}
}
void ch1_on(){
for(int i=72;i<80;i++){
pixels.setPixelColor(i, pixels.Color(random(50),random(100),random(150))); // Moderately bright green color.
pixels.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}
void ch1_off(){
for(int i=72;i<80;i++){
pixels.setPixelColor(i, pixels.Color(0,0,0)); // Moderately bright green color.
pixels.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}
void ch2_on(){
for(int i=64;i<72;i++){
pixels.setPixelColor(i, pixels.Color(random(50),random(100),random(150))); // Moderately bright green color.
pixels.setPixelColor(i+16, pixels.Color(random(50),random(100),random(150)));
pixels.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}
void ch2_off(){
for(int i=64;i<72;i++){
pixels.setPixelColor(i, pixels.Color(0,0,0)); // Moderately bright green color.
pixels.setPixelColor(i+16, pixels.Color(0,0,0));
pixels.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}
void ch3_on(){
for(int i=0;i<10;i++){
pixels.setPixelColor(i, pixels.Color(random(50),random(100),random(150))); // Moderately bright green color.
pixels.setPixelColor(i+53, pixels.Color(random(50),random(100),random(150)));
pixels.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}
void ch3_off(){
for(int i=0;i<10;i++){
pixels.setPixelColor(i, pixels.Color(0,0,0)); // Moderately bright green color.
pixels.setPixelColor(i+53, pixels.Color(0,0,0));
pixels.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}
void ch4_on(){
for(int i=11;i<23;i++){
pixels.setPixelColor(i, pixels.Color(random(50),random(100),random(150))); // Moderately bright green color.
pixels.setPixelColor(i+29, pixels.Color(random(50),random(100),random(150)));
pixels.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}
void ch4_off(){
for(int i=11;i<23;i++){
pixels.setPixelColor(i, pixels.Color(0,0,0)); // Moderately bright green color.
pixels.setPixelColor(i+29, pixels.Color(0,0,0));
pixels.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}
void ch5_on(){
for(int i=24;i<39;i++){
pixels.setPixelColor(i, pixels.Color(random(50),random(100),random(150))); // Moderately bright green color.
pixels.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}
void ch5_off(){
for(int i=24;i<39;i++){
pixels.setPixelColor(i, pixels.Color(0,0,0)); // Moderately bright green color.
pixels.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}
- 01. Concept
- 02. Make Kabuto
- 03. Make Curcuits
- 04. Final Result