Created
June 27, 2009 07:22
-
-
Save koki-h/136934 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
//ナイトライダーその3。滑らかな感じになるようにした | |
#define PIN_MIN 0 | |
#define PIN_MAX 5 | |
#define NUM_OF_PINS 6//何回も使う値はマクロにして即値にしたほうが速い | |
int apin[] = {3,5,6,9,10,11}; | |
#define NUM_OF_STATES 14 | |
int state[NUM_OF_STATES][NUM_OF_PINS] = { | |
{0,0,0,0,0,0}, | |
{0,0,0,0,0,1}, | |
{0,0,0,0,1,2}, | |
{0,0,0,1,2,3}, | |
{0,0,1,2,3,4}, | |
{0,1,2,3,4,3}, | |
{1,2,3,4,3,2}, | |
{2,3,4,3,2,1}, | |
{3,4,3,2,1,0}, | |
{4,3,2,1,0,0}, | |
{3,2,1,0,0,0}, | |
{2,1,0,0,0,0}, | |
{1,0,0,0,0,0}, | |
{0,0,0,0,0,0}}; | |
void setup() | |
{ | |
for (int i = PIN_MIN; i <= PIN_MAX; i++){ | |
pinMode(apin[i], OUTPUT); | |
} | |
} | |
void set_state(int state_idx){ | |
for (int j = PIN_MIN; j <= PIN_MAX ; j++){ | |
analogWrite(apin[j], state[state_idx][j] * 63 ); | |
} | |
} | |
void loop() | |
{ | |
for (int i = 0; i < NUM_OF_STATES; i++){ | |
set_state(i); | |
delay(100); | |
} | |
for (int i = NUM_OF_STATES - 1; i > 0 ; i--){ | |
set_state(i); | |
delay(100); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment