단순한 애니메이션
News/Events 2007. 10. 16. 18:12arduino를 활용한 간단한 애니메이션
코드는 아래와 같으며, 기본적으로 3개의 이미지 파일을 연속해서 보여주는 코드이다.
//****************************//
//**********************************//
// Name : shiftOutCode, Hello World //
// Author : Carlyn Maw,Tom Igoe //
// Date : 25 Oct, 2006 //
// Version : 1.0 //
// Notes : Code for using a 74HC595 Shift Register //
// : to count from 0 to 255 //
//****************************************************************
//Pin connected to ST_CP of 74HC595
int latchPin = 7;
//Pin connected to SH_CP of 74HC595
int clockPin = 6;
////Pin connected to DS of 74HC595
int dataPin = 5;
int numSymbols = 3;
int icon[] = {
B11111111, // I
B11111111,
B00011000,
B00011000,
B00011000,
B00011000,
B11111111,
B11111111,
B00111100, // Love
B11111111,
B11111111,
B01111110,
B00111100,
B00011000,
B00011000,
B00000000,
B11000011, // U
B11000011,
B11000011,
B11000011,
B11000011,
B11000011,
B01100110,
B00111100
};
// FUNCTIONS
void anim2() {
for (int j = 0; j < numSymbols; j++) {
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, icon[7+8*j]);
shiftOut(dataPin, clockPin, MSBFIRST, icon[6+8*j]);
shiftOut(dataPin, clockPin, MSBFIRST, icon[5+8*j]);
shiftOut(dataPin, clockPin, MSBFIRST, icon[4+8*j]);
shiftOut(dataPin, clockPin, MSBFIRST, icon[3+8*j]);
shiftOut(dataPin, clockPin, MSBFIRST, icon[2+8*j]);
shiftOut(dataPin, clockPin, MSBFIRST, icon[1+8*j]);
shiftOut(dataPin, clockPin, MSBFIRST, icon[8*j]);
digitalWrite(latchPin, HIGH);
delay(1300);
Serial.println(icon[2+8*j], BIN);
Serial.println(icon[1+8*j], BIN);
Serial.println(icon[8*j], BIN);
Serial.println("**********");
}
}
// END FUNCTIONS
void setup() {
//set pins to output because they are addressed in the main loop
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
anim2();
delay(500);
}
작동되면 다음과 같다.