void scrolling(int x, int y, const unsigned char *bitmap, int delay_time, int speed)
- 로봇의 표정을 표현하기 위한 가장 기본적인 함수.
이미지를 출력 위치 좌표
보여줄 비트맵
연속으로 보여지는 비트맵 사이의 시간
- 비트맵을 몇번 보여주는지 정해주는 값
- 눈의 속도 결정에 압도적이다.
- 보여줄 비트맵 수 = 임의 값 / speed 이기에 값이 커질 수록 빨라진다.
int now_eyes_x = 0;// 전역변수
int now_eyes_y = 0;
void scrolling(int x, int y, const unsigned char * bitmap, int delay_time, int speed)
{
int count;
int now_x;
int now_y;
now_x = (x - now_eyes_x) / speed;
now_y = (y - now_eyes_y) / speed;
count = (abs(now_x) >= abs(now_y)) ? now_x : now_y;
count = (count >= 0) ? count : -count;
for (int i = 1; i <= count + 1; i++)
{
display.clearDisplay();
display.drawBitmap(now_eyes_x + i * (x - now_eyes_x)/count, now_eyes_y + i * (y - now_eyes_y)/count , bitmap, 128, 64, 1);
display.display();
delay(delay_time);
}
now_eyes_x = x;
now_eyes_y = y;
}
전역변수로 현재 눈의 위치를 알고,
위치에 따라 천천히 옮겨가는 방식이다.
갑자기 순간이동 되는 애니메이션을 방지한다.
void eyes_cross()
{
scrolling(25, -17, epd_bitmap_ROBOT, 5, 5);
scrolling(-25, -17, epd_bitmap_ROBOT, 5, 5);
scrolling(25, 17, epd_bitmap_ROBOT, 5, 5);
}
void eyes_earth_quake(int time)
{
for (int i = 0; i < time; i++)
{
scrolling(10, 0, epd_bitmap_ROBOT, 5, 5);
delay(200);
scrolling(-10, 0, epd_bitmap_ROBOT, 5, 5);
delay(200);
}
}
void loop() {
scrolling(0, 0, epd_bitmap_ROBOT, 5, 5);
delay(2000);
eyes_earth_quake(4);
delay(1000);
eyes_cross();
delay(1000);
}
저번 페이지에서 사용했던 코드보다
훨씬 편해진 것을 알 수 있다.