4

用Arduino实现跨年倒计时

 1 year ago
source link: https://blog.csdn.net/qq_51405411/article/details/111398123
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

用Arduino实现跨年倒计时

在2021年到来之际,用Arduino实现新年倒计时。

一、设计思路

使用 按键 控制倒计时,从10倒计时1,然后 在OLED屏幕上显示“烟花”图像和“新年好”的图像,与此同时蜂鸣器播放“新年好”歌曲以及六个LED“星型”灯火显示。当歌曲播放结束后,屏幕显示文字“没看够?再来一次”。再按一次按键开关,灯光熄灭以及重新倒计时。

整体实物图
2-7管脚——LED小灯;
8管脚——蜂蜜器;
12管脚——按键。
OLED 屏幕端口和管脚连接图

二、程序如下

#include "U8glib.h"//使用u8g类库
U8GLIB_SSD1306_128X64 u8g(13,11,10,9); //OLED显示屏对应管脚
int i,j,k;
int buzzerPin=8;//蜂鸣器连接管脚
int buttonPin = 12;//按键检测管脚
int KEY_NUM=0;
int a[48]={523,523,523,523,392,392,659,659,659,659,523,523,
523,659,784,784,784,784,698,659,587,587,587,587,//《新年好》歌曲对应频率
587,659,698,698,698,698,659,587,659,659,523,523,
523,659,587,587,392,392,494,587,523,523,523,523};

void scanKey()
{
  if(digitalRead(buttonPin)==LOW){     
    delay(20);                  //按键防抖动程序
    if(digitalRead(buttonPin)==LOW){
      while(digitalRead(buttonPin)==LOW);    //按键被按下KEY_NUM就会+1
      KEY_NUM++;    }}
}

static const unsigned char x1[]PROGMEM={//《烟花图片》对应fritzing取模
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x60,0x00,0x00,0x00,0x0F,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x80,0x01,0x00,0xC0,0x00,0x00,0x00,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x08,0x03,0x38,0x80,0xFF,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x08,0x20,0x04,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,
0x00,0x20,0x00,0x10,0x98,0x03,0x00,0x00,0x00,0x02,0x10,0x00,0x06,0x06,0x0C,0x00,
0x00,0x00,0x00,0x10,0x48,0x00,0x00,0x00,0x00,0x0C,0x20,0x80,0x01,0x01,0x03,0x00,
0x00,0x00,0x00,0x21,0x28,0x00,0x00,0x00,0x00,0x30,0x20,0xC0,0xC0,0x80,0x00,0x00,
0x00,0x80,0x07,0x20,0x1C,0x20,0x00,0x00,0x00,0x42,0x20,0x24,0x20,0x60,0x00,0x00,
0x80,0x0F,0x64,0x20,0x04,0x1C,0x00,0x00,0x30,0x46,0x40,0x04,0x10,0x18,0x00,0x00,
0x60,0x80,0xC0,0x60,0x06,0x03,0x80,0x07,0x60,0x98,0x42,0x04,0x08,0x06,0x00,0x00,
0x20,0x00,0x80,0x61,0xE2,0x00,0x7E,0x00,0x84,0x21,0x87,0x04,0x06,0x01,0x00,0x7C,
0x00,0x00,0x00,0xA1,0x19,0x00,0x01,0x00,0x0C,0x41,0x8C,0x04,0x82,0x00,0x80,0x03,
0x00,0x00,0x00,0xA2,0x0D,0x00,0x00,0x00,0x30,0x82,0x98,0x04,0x41,0x00,0x63,0x00,
0x00,0x00,0x40,0xA6,0x05,0x00,0x00,0x00,0x40,0x04,0x99,0x84,0x20,0xF8,0x18,0x00,
0x00,0x00,0x04,0xA4,0x00,0xFF,0x01,0x00,0x80,0x09,0x91,0x44,0x10,0x07,0x06,0x00,
0x80,0x00,0x00,0xAC,0xFC,0x00,0xC0,0x01,0x00,0x32,0x32,0x24,0xD0,0x80,0x01,0x00,
0x60,0x7C,0x00,0xB8,0x00,0x00,0x00,0x07,0x00,0x2C,0x74,0x24,0x60,0x61,0x00,0x00,
0x38,0x00,0xFE,0xB0,0x00,0x00,0x00,0x38,0x00,0x50,0x58,0x94,0x80,0x20,0x00,0x00,
0x38,0x00,0x80,0xB3,0x1E,0x00,0x00,0xF0,0x03,0xA0,0x58,0xD4,0x70,0x10,0x00,0x00,
0x14,0x00,0x00,0x22,0xFE,0x1F,0x00,0x00,0x0C,0x40,0x01,0x34,0x08,0x0C,0x00,0x00,
0x06,0x00,0x00,0x00,0x00,0xE0,0x00,0x00,0x30,0x80,0x00,0x1C,0x04,0x1C,0x00,0x00,
0x02,0x00,0xF0,0x07,0x00,0x00,0x07,0x00,0x40,0x3F,0x01,0x0E,0xC3,0x03,0x00,0x00,
0x00,0x00,0x0C,0x70,0x80,0x00,0x1C,0x00,0x80,0x01,0x06,0x00,0x41,0x02,0x00,0x00,
0x00,0x10,0x06,0x80,0x81,0x01,0x00,0x00,0xFE,0x07,0x04,0x80,0x00,0x01,0x00,0x00,
0x00,0x80,0x01,0x00,0x0E,0x30,0x00,0xF0,0x11,0x03,0x3B,0x40,0x80,0xE0,0xFF,0x1F,
0x00,0x00,0x00,0x07,0x08,0xE0,0x00,0x0F,0x0C,0x80,0x2F,0x40,0x80,0x00,0x00,0x60,
0x00,0x3E,0x80,0x00,0x10,0x00,0xC1,0x00,0x06,0xE0,0x01,0x40,0x80,0x00,0x00,0x80,
0xC0,0x01,0x40,0x00,0x60,0x00,0x3E,0x00,0x60,0x30,0x00,0x1E,0x40,0x00,0x00,0x00,
0x00,0x00,0x20,0x00,0x81,0x00,0x0E,0x00,0x10,0x10,0x00,0x3F,0x40,0x00,0x00,0x00,
0x30,0x00,0x10,0x00,0x01,0x01,0x11,0x00,0x08,0x08,0xC0,0x7F,0x40,0x00,0x00,0x00,
0x10,0x00,0x0C,0x10,0x02,0x0A,0x20,0x00,0x84,0x0C,0xC0,0x73,0x00,0xFE,0x00,0x00,
0x10,0x00,0x04,0x10,0x02,0x06,0x40,0x00,0x42,0x04,0xC0,0x73,0x00,0x00,0x0F,0x00,
0x00,0x00,0x02,0x10,0x04,0x08,0x80,0x00,0x21,0x04,0xC8,0x7F,0x00,0x00,0x70,0x00,
0x00,0x00,0x22,0x08,0x04,0x08,0x00,0x01,0x11,0x04,0x48,0x3F,0x00,0x00,0x80,0x01,
0x00,0x00,0x01,0x08,0x04,0x10,0x00,0x83,0x08,0x00,0x4F,0x1E,0x00,0x00,0x00,0x03,
0x10,0x00,0x01,0x08,0x89,0x10,0x10,0x42,0x08,0x80,0x45,0x00,0x00,0x00,0x00,0x04,
0x10,0x88,0x00,0x08,0x08,0x10,0x00,0x20,0x04,0xC4,0x42,0x00,0xC0,0x1F,0x00,0x0C,
0x10,0x80,0x00,0x08,0x08,0x20,0x00,0x24,0x04,0x24,0x42,0x00,0x00,0x60,0x00,0x08,
0x08,0x80,0x00,0x04,0x11,0x40,0x00,0x14,0x04,0x22,0x42,0x02,0x06,0x80,0x01,0x00,
0x08,0x80,0x00,0x04,0x11,0x80,0x00,0x0C,0x00,0x11,0x42,0x06,0x18,0x00,0x06,0x00,
0x08,0x40,0x00,0x04,0x00,0x80,0x00,0x08,0x00,0x11,0x41,0x04,0x60,0x00,0x0C,0x00,
0x08,0x40,0x00,0x04,0x00,0x80,0x01,0x08,0x80,0x08,0x41,0x04,0x80,0x00,0x10,0x00,
0x08,0x40,0x00,0x05,0x00,0x00,0x01,0x04,0x40,0x08,0x81,0x08,0x00,0x01,0x33,0x00,
0x08,0x40,0x00,0x04,0x00,0x00,0x00,0x04,0x40,0x84,0x80,0x08,0x00,0x02,0x26,0x00,
0x00,0x00,0x00,0x04,0x10,0x00,0x00,0x08,0x20,0x84,0x80,0x08,0x00,0x04,0x08,0x00,
0x00,0x00,0x00,0x04,0x00,0x00,0x04,0x08,0x10,0x84,0x80,0x08,0x00,0x08,0x08,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x84,0x80,0x10,0x00,0x10,0x10,0x00,
0x00,0x20,0x00,0x00,0x10,0x00,0x00,0x00,0x08,0x82,0x00,0x11,0x04,0x20,0x10,0x00,
0x00,0x20,0x00,0x04,0x30,0x00,0x00,0x00,0x08,0x82,0x00,0x21,0x08,0x40,0x30,0x00,
0x00,0x20,0x00,0x04,0x20,0x00,0x00,0x00,0x08,0x82,0x80,0x20,0x08,0x40,0x00,0x00,
0x00,0x20,0x00,0x0C,0x20,0x00,0x00,0x00,0x04,0x82,0x80,0x40,0x08,0x80,0x00,0x00,
0x00,0x20,0x00,0x08,0x20,0x00,0x00,0x00,0x04,0x82,0x80,0x40,0x08,0x00,0x01,0x00,
0x00,0x20,0x00,0x08,0x20,0x00,0x00,0x00,0x02,0x82,0x80,0x80,0x10,0x00,0x02,0x00,
0x00,0x20,0x00,0x08,0x00,0x00,0x00,0x00,0x02,0x84,0x80,0x80,0x30,0x00,0x04,0x00,
0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x84,0x80,0x81,0x60,0x00,0x0C,0x00,
0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x01,0x81,0x01,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x02,0x01,0x06,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x0C,0x01,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x02,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x02,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x02,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,
  
};
static const unsigned char x2[]PROGMEM={//《新年快乐》对应fritzing取模
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0xE0,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,
0x00,0x00,0xC0,0xFF,0xFF,0x07,0x00,0x00,0x00,0x00,0xFE,0xFF,0x3F,0x00,0x00,0x00,
0x00,0x00,0xF8,0xFF,0xFF,0x3F,0x00,0x00,0x00,0xC0,0xFF,0xFF,0xFF,0x01,0x00,0x00,
0x00,0x00,0xFE,0xFF,0xFF,0xFF,0x01,0x00,0x00,0xF8,0xFF,0xFF,0xFF,0x07,0x00,0x00,
0x00,0x80,0xFF,0xFF,0xFF,0xFF,0x0F,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x1F,0x00,0x00,
0x00,0xE0,0xFF,0x0F,0xE0,0xFF,0x3F,0x00,0x80,0xFF,0xFF,0x00,0xFF,0x7F,0x00,0x00,
0x00,0xF0,0x7F,0x00,0x00,0xFC,0x7F,0x00,0xE0,0xFF,0x01,0x00,0xE0,0xFF,0x00,0x00,
0x00,0xF8,0x0F,0x00,0x00,0xC0,0xFF,0x01,0xF8,0x3F,0x00,0x00,0x00,0xFF,0x01,0x00,
0x00,0xFC,0x03,0x00,0x00,0x00,0xFF,0x03,0xFC,0x0F,0x00,0x00,0x00,0xFC,0x03,0x00,
0x00,0xFE,0x00,0x00,0x00,0x00,0xFC,0x07,0xFE,0x03,0x00,0x00,0x00,0xF0,0x07,0x00,
0x00,0x7F,0x00,0x00,0x00,0x00,0xF0,0x0F,0xFF,0x00,0x00,0x00,0x00,0xE0,0x0F,0x00,
0x00,0x3F,0x00,0x00,0x00,0x00,0xC0,0x9F,0x3F,0x00,0x00,0x00,0x00,0xC0,0x0F,0x00,
0x80,0x1F,0x00,0x00,0x00,0x00,0x80,0xFF,0x1F,0x00,0x00,0x00,0x00,0x80,0x1F,0x00,
0x80,0x0F,0x00,0x00,0x00,0x00,0x00,0xFF,0x0F,0x00,0x00,0x00,0x00,0x00,0x1F,0x00,
0x80,0x0F,0x00,0x00,0x00,0x00,0x00,0xFE,0x07,0x00,0x00,0x00,0x00,0x00,0x1F,0x00,
0xC0,0x0F,0x00,0x00,0x00,0x00,0x00,0xFC,0x03,0x00,0x00,0x00,0x00,0x00,0x3F,0x00,
0xC0,0x07,0x00,0x08,0x00,0x00,0x00,0xF8,0x01,0x00,0x00,0x00,0x00,0x00,0x3E,0x00,
0xC0,0x07,0x00,0x18,0x80,0x03,0x01,0xF0,0x04,0x04,0x00,0x80,0x0F,0x00,0x3E,0x00,
0x80,0x07,0x00,0x10,0x7C,0x80,0x00,0x00,0x04,0x04,0xC0,0x7F,0x00,0x00,0x3E,0x00,
0x80,0x0F,0x00,0xFF,0x05,0x80,0xFF,0x3F,0x04,0x04,0x40,0x00,0x00,0x00,0x3E,0x00,
0x80,0x0F,0x00,0x82,0x04,0x40,0x40,0x00,0xCC,0xFF,0x40,0x20,0x00,0x00,0x1F,0x00,
0x80,0x0F,0x00,0x46,0x04,0x40,0x40,0x00,0x1D,0x84,0x60,0x20,0x00,0x00,0x1F,0x00,
0x80,0x1F,0x00,0x24,0x04,0x20,0x40,0x00,0x35,0x84,0x60,0x20,0x00,0x00,0x1F,0x00,
0x00,0x1F,0x80,0xFF,0x05,0x30,0x40,0x00,0x25,0x84,0x60,0x20,0x00,0x80,0x1F,0x00,
0x00,0x3F,0x00,0x00,0xFC,0x93,0xFF,0xBF,0x04,0x84,0x60,0x20,0x00,0xC0,0x0F,0x00,
0x00,0x3F,0x00,0x10,0x44,0x80,0x40,0x80,0x04,0x84,0xE0,0xFF,0x3F,0xC0,0x0F,0x00,
0x00,0x7E,0x00,0x10,0x44,0x80,0x40,0x80,0x04,0x84,0x00,0x20,0x00,0xE0,0x07,0x00,
0x00,0xFC,0x00,0xFF,0x44,0x80,0x40,0x00,0xE4,0xFF,0x03,0x21,0x02,0xF0,0x03,0x00,
0x00,0xFC,0x01,0x10,0x44,0x80,0x40,0x00,0x04,0x0C,0x80,0x21,0x04,0xF8,0x03,0x00,
0x00,0xF8,0x03,0x52,0x44,0xF0,0xFF,0x7F,0x04,0x0A,0xC0,0x20,0x0C,0xFC,0x01,0x00,
0x00,0xF0,0x07,0x51,0x42,0x00,0x40,0x00,0x04,0x1A,0x60,0x20,0x18,0xFE,0x00,0x00,
0x00,0xE0,0x0F,0x91,0x42,0x00,0x40,0x00,0x04,0x11,0x30,0x20,0x30,0x7F,0x00,0x00,
0x00,0xC0,0x9F,0x90,0x43,0x00,0x40,0x00,0x84,0x31,0x18,0x20,0xE0,0x3F,0x00,0x00,
0x00,0x80,0x3F,0x10,0x41,0x00,0x40,0x00,0xC4,0x60,0x08,0x20,0xC0,0x3F,0x00,0x00,
0x00,0x00,0xFF,0x8F,0x40,0x00,0x40,0x00,0x64,0xC0,0x01,0x1E,0xF0,0x1F,0x00,0x00,
0x00,0x00,0xFE,0x01,0x00,0x00,0x00,0x00,0x34,0x00,0x03,0x00,0xF8,0x07,0x00,0x00,
0x00,0x00,0xFC,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x03,0x00,0x00,
0x00,0x00,0xF8,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x01,0x00,0x00,
0x00,0x00,0xE0,0x3F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x7F,0x00,0x00,0x00,
0x00,0x00,0xC0,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0x3F,0x00,0x00,0x00,
0x00,0x00,0x00,0xFF,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0x0F,0x00,0x00,0x00,
0x00,0x00,0x00,0xFE,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x07,0x00,0x00,0x00,
0x00,0x00,0x00,0xF8,0x3F,0x00,0x00,0x00,0x00,0x00,0x80,0xFF,0x01,0x00,0x00,0x00,
0x00,0x00,0x00,0xE0,0xFF,0x00,0x00,0x00,0x00,0x00,0xF0,0x7F,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0xC0,0xFF,0x03,0x00,0x00,0x00,0x00,0xFC,0x3F,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0xFF,0x1F,0x00,0x00,0x00,0x80,0xFF,0x0F,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0xFC,0xFF,0x00,0x00,0x00,0xE0,0xFF,0x03,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0xE0,0xFF,0x03,0x00,0x00,0xFC,0x7F,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x80,0xFF,0x1F,0x00,0x80,0xFF,0x1F,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xFE,0xFF,0x01,0xF8,0xFF,0x07,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xF0,0xFF,0x0F,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x80,0xFF,0xFF,0xFF,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0xFF,0xFF,0x07,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};


static const unsigned char x3[]PROGMEM={//《没看够,再来一次》对应fritzing取模
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x08,0x00,0x00,0xC0,0x83,0x80,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x30,0xFE,0xE0,0x3F,0xC0,0xC0,0xC0,0x07,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x20,0x82,0x00,0x0C,0xC0,0xCF,0x4F,0x08,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x82,0xE0,0xFF,0x23,0x28,0x0C,0x18,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x08,0x83,0x07,0x06,0x20,0x18,0x06,0x18,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x98,0x01,0x00,0x02,0xF0,0xC9,0x03,0x08,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x20,0x00,0xF0,0xFF,0x2F,0x89,0x01,0x0C,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0xFF,0x01,0x01,0x20,0x69,0x01,0x06,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x20,0x82,0x81,0xFF,0x23,0xB9,0x01,0x03,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x30,0x82,0xC0,0x00,0x22,0x89,0x1F,0x03,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x10,0x44,0xB0,0xFF,0x23,0x49,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x10,0x38,0x98,0x00,0xE2,0x29,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x18,0x38,0x80,0xFF,0x23,0x98,0x03,0x03,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x08,0xC6,0x80,0x00,0x02,0x84,0x01,0x03,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0xC8,0x01,0x87,0xFF,0x03,0x64,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x82,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0xC0,0xFF,0x1F,0x40,0x00,0x00,0x00,0x02,0x01,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x20,0x00,0xFF,0x3F,0x00,0x00,0x86,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x20,0x00,0x40,0x00,0x00,0x00,0x8C,0xFF,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0xFF,0x07,0x42,0x08,0x00,0x00,0x48,0xC0,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x21,0x04,0x44,0x0C,0x00,0x00,0x40,0x44,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x21,0x04,0x48,0x02,0x00,0x00,0x20,0x44,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0xFF,0x07,0x40,0x80,0xFF,0xFF,0x00,0x66,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x21,0x84,0xFF,0x3F,0x00,0x00,0x18,0x06,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x21,0x04,0xE0,0x00,0x00,0x00,0x08,0x0A,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x21,0x04,0x50,0x01,0x00,0x00,0x04,0x0A,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0xE0,0xFF,0x3F,0x48,0x02,0x00,0x00,0x04,0x11,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x01,0x04,0x46,0x04,0x00,0x00,0x82,0x10,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x01,0x04,0x41,0x18,0x00,0x00,0x42,0x20,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x01,0xC4,0x40,0x60,0x00,0x00,0x20,0xC0,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x81,0x07,0x40,0x00,0x00,0x00,0x18,0x80,0x01,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};

void draw1(){u8g.drawXBMP(0,0,128,64,x1);}//将三个数组放入三个函数中
void draw2(){u8g.drawXBMP(0,0,128,64,x2);}
void draw3(){u8g.drawXBMP(0,0,128,64,x3);}

void setup()
{
  for(i=2;i<=7;i++)
  pinMode(i,OUTPUT);//LED小灯管脚定义为输出
  pinMode(buttonPin,INPUT_PULLUP); //按键管脚定义为输入
  pinMode(buzzerPin,OUTPUT);//蜂鸣器管脚定义为输出
  }
 void loop()
{
  scanKey();//按键函数
  if(KEY_NUM%2==1){
     for(k=9;k>=1;k--){//进入倒计时
    u8g.firstPage();
  do{
     u8g.setPrintPos(50,50);
     u8g.setFont(u8g_font_fub30);
      u8g.print(k);
    }while(u8g.nextPage()); 

    tone(buzzerPin,700);//倒计时同时蜂鸣器发出500ms声音
  delay(500);
  noTone(buzzerPin);
   delay(500);} 

u8g.firstPage();do draw1();while(u8g.nextPage());
//显示烟花图片
  for(i=2;i<=3;i++)//小灯依次点亮
{digitalWrite(2,1);
  delay(200);
  digitalWrite(3,1);
  digitalWrite(4,1);
  delay(200);
  digitalWrite(5,1);
  digitalWrite(6,1);
  delay(200);
  digitalWrite(7,1);
  delay(200);
 }

u8g.firstPage();do draw2();while(u8g.nextPage()); 
//第二张图片《新年快乐》
 for(i=2;i<=7;i++)
   digitalWrite(i,0);
   delay(100);
  digitalWrite(2,1);
  delay(100);
  digitalWrite(3,1);
  digitalWrite(4,1);
  delay(100);
  digitalWrite(5,1);
  digitalWrite(6,1);
  delay(100);
  digitalWrite(7,1);
  delay(300);
//再次点亮  
u8g.firstPage();do draw1();while(u8g.nextPage());
for(int i=2;i<=11;i++)//蜂鸣器第一句歌词
  {tone(buzzerPin,a[i]);
  delay(250);}
for(i=2;i<=7;i++)
   digitalWrite(i,0);
   delay(250);
for(j=0;j<=2;j++)
 {for(i=2;i<=7;i++)
   digitalWrite(i,1); 
   delay(100);
  }
 u8g.firstPage();do draw2();while(u8g.nextPage());  
  for(int i=12;i<=21;i++)//第二句
  {tone(buzzerPin,a[i]);
  delay(250);}
 for(i=2;i<=7;i++)
  digitalWrite(i,0);
  delay(200);
digitalWrite(2,1);
  delay(100);
  digitalWrite(3,1);
  digitalWrite(4,1);
  delay(100);
  digitalWrite(5,1);
  digitalWrite(6,1);
  delay(100);
  digitalWrite(7,1);
  delay(300);
u8g.firstPage();do draw1();while(u8g.nextPage());  
  for(int i=24;i<=35;i++)//第三句
  {tone(buzzerPin,a[i]);
  delay(250);}
for(i=2;i<=7;i++)
   digitalWrite(i,0);
   delay(100);
for(j=0;j<=2;j++)
 {for(i=2;i<=7;i++)
   digitalWrite(i,1); 
   delay(100);
   }
   u8g.firstPage();do draw2();while(u8g.nextPage());  
  for(int i=36;i<=45;i++)//第四句
  {tone(buzzerPin,a[i]);
  delay(250);}
  delay(1000);
  noTone(buzzerPin);
  u8g.firstPage();do draw3();while(u8g.nextPage()); 
//播放完之后显示图片《没看够?再来一次》
  }else{
noTone(buzzerPin);
for(i=2;i<=7;i++)//再按一次,灯光熄灭
   digitalWrite(i,0);
   delay(100);
u8g.firstPage();do draw3();while(u8g.nextPage());    
}}

一学期Arduino获益匪浅,为以后嵌入式学习打下了一个很好的基础,收官!
同时祝大家新年快乐,事事开心!!!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK