Skip to content

Instantly share code, notes, and snippets.

@mia-0032
Created December 25, 2012 18:25
Show Gist options
  • Save mia-0032/4374651 to your computer and use it in GitHub Desktop.
Save mia-0032/4374651 to your computer and use it in GitHub Desktop.
LEDサイリウムを作った時にArduinoに書き込んだコード。 記事:http://make-audio.blogspot.jp/2011/08/led.html
#define redLedPin 3
#define greenLedPin 5
#define blueLedPin 9
#define switchPin 2
int mode = 2;
int colorMax = 9;
int colorArray[][3]={{255,0,2},
{220,200,0},
{0,255,0},
{0,255,200},
{0,0,255},
{170,0,255},
{150,255,200},
{255,150,10},
{255,80,70}};
int i = 0;
int modeMax = colorMax + mode;
void setup(){
pinMode(switchPin,INPUT);
}
void loop(){
if(digitalRead(switchPin)==HIGH){
upCount();
delay(300);
}
if(i < colorMax){
color(i);
}else if(i == colorMax){
colorChange();
}else if(i == colorMax + 1){
color(random(0,colorMax));
}
delay(100);
}
void upCount(){
i++;
if(i >= modeMax){i=0;}
}
void color(int num){
analogWrite(redLedPin,colorArray[num][0]);
analogWrite(greenLedPin,colorArray[num][1]);
analogWrite(blueLedPin,colorArray[num][2]);
}
void colorChange(){
static int red = 250;
static int green = 0;
static int blue = 0;
if(red > 0 && blue == 0){
red -= 10;
green += 10;
}else if(green > 0){
green -= 10;
blue += 10;
}else{
blue -=10;
red +=10;
}
analogWrite(redLedPin,red);
analogWrite(greenLedPin,green);
analogWrite(blueLedPin,blue);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment