江苏科技大学“FlySpiders”本创小组组员学习记录----王澳刚

 #include "U8glib.h"
#include 
#include 
#define button 5
//在朱玉馨的帮助下完成的找调子
  #define NOTE_L0 -1
  #define NOTE_C1 262
  #define NOTE_C2 294
  #define NOTE_C3 330
  #define NOTE_C4 350
  #define NOTE_C5 393
  #define NOTE_C6 441
  #define NOTE_C7 495
  #define NOTE_H1 525
  #define NOTE_HH1 1109
  #define NOTE_H2 589
  #define NOTE_HH2 1245
  #define NOTE_H3 661
  #define NOTE_H4 700
  #define NOTE_H5 786
  #define NOTE_H6 882
  #define NOTE_H7 990  //以上就是C大调对应的频率,搞音乐的都是有才华的人
#define WHOLE 1
#define HALF 0.5
#define QUARTER 0.25
#define EIGHTH .25
#define SIXTEENTH 0.625
DS3231 Clock;
bool Century=false;
bool h12;
bool PM;
byte ADay, AHour, AMinute, ASecond, ABits;
bool ADy, A12h, Apm;
int second,minute,hour,date,month,year,temperature; 
static unsigned char u8g_logo_du[] U8G_PROGMEM ={  
0x00,0x00,0x32,0x4D,0x0A,0x08,0x48,0x30};
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE);

我的手机 2017/5/30 14:28:00

int tune[] = NOTE_L0,NOTE_H1,NOTE_H1,NOTE_C7,NOTE_H1,NOTE_L0,NOTE_C7,NOTE_H1,NOTE_C7,NOTE_H1,NOTE_L0,NOTE_H2,           
NOTE_L0,NOTE_C7,NOTE_C7,NOTE_C6,NOTE_C7,NOTE_L0,NOTE_C6,NOTE_C7,NOTE_C6,NOTE_C7,NOTE_L0,NOTE_H1,
NOTE_L0,NOTE_C6,NOTE_H1,NOTE_H3,NOTE_H2,NOTE_H1,NOTE_H3,
NOTE_H3,NOTE_H3,NOTE_H3,NOTE_L0,
NOTE_L0,NOTE_H1,NOTE_H1,NOTE_C7,NOTE_H1,NOTE_L0,NOTE_C7,NOTE_H1,NOTE_C7,NOTE_H1,NOTE_L0,NOTE_H2,
NOTE_L0,NOTE_C7,NOTE_C7,NOTE_C6,NO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序列定义为tune,整数

我的手机 2017/5/30 14:28:06

float duration[]=0.25,0.25,0.25,0.25,0.5,0.25,0.25,0.25,0.25,0.5,0.5,0.5,
0.25,0.25,0.25,0.25,0.5,0.25,0.25,0.25,0.25,0.5,0.5,0.5,
1,0.5,0.5,0.5,0.5,0.5,0.5,
1,1,1,1,
0.25,0.25,0.25,0.25,0.5,0.25,0.25,0.25,0.25,0.5,0.5,0.5,
0.25,0.25,0.25,0.25,0.5,0.25,0.25,0.25,0.25,0.5,0.5,0.5,
1,0.5,0.5,0.5,0.5,0.5,0.5,
1,1,1,0.5,0.5,
0.5,0.5,0.5,0.5,1,0.5,0.5,
0.5,0.5,0.5,0.5,1,0.5,0.5,
0.5,0.5,0.5,0.5,1,0.5,0.5,
0.5,0.5,0.5,0.5,1,0.5,0.5,
0.5,0.5,0.5,0.5,1,0.5,0.5,
0.5,0.5,0.5,0.5,1,0.5,0.5,
 0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,
 1,1,
 0.5,0.5,0.5,0.5,
 1,0.5,0.5,0.5,0.5,1,
 1,0.5,0.5,0.5,0.5,1,
 1,0.5,0.5,0.5,0.5,0.5,0.5,
 1,1,0.5,0.5,0.5,0.5,
 1,0.5,0.5,0.5,0.5,1,
 1,0.5,0.5,0.5,0.5,1,
 1,0.5,0.5,0.5,0.5,0.5,0.5,
 1,1,1,1};

我的手机 2017/5/30 14:28:11

int length;
int tonePin=7;
void setup()
{ Clock.setClockMode(true);
  pinMode(tonePin,OUTPUT);
  pinMode(button,INPUT_PULLUP);
  pinMode(2,OUTPUT);
   pinMode(3,OUTPUT);
    pinMode(4,OUTPUT);
  length = sizeof(tune)/sizeof(tune[0]);
}
14:28:16
我的手机 2017/5/30 14:28:16

void loop()
{  second=Clock.getSecond();             
  minute=Clock.getMinute();              
  hour=Clock.getHour(h12, PM);           
  date=Clock.getDate();                 
  month=Clock.getMonth(Century);        
  year=Clock.getYear();                  
  temperature=Clock.getTemperature(); 
  u8g.firstPage();                             
  do { draw(); 
dobutton();} while( u8g.nextPage() );
  
}

我的手机 2017/5/30 14:28:21

void draw(void) {
 u8g.setFont(u8g_font_freedoomr10r);
 u8g.setPrintPos(0,17);
 u8g.print(year);
  u8g.drawLine(14,10,16,10);
  u8g.setPrintPos(18,17);
  u8g.print(month/10);
  u8g.print(month%10);
  u8g.drawLine(32,10,34,10);
  u8g.setPrintPos(36,17);
   u8g.print(date);
    u8g.setPrintPos(60,17);
    u8g.print("T:");
   u8g.setPrintPos(82,17);
   u8g.print(temperature);
   u8g.drawXBMP( 96, 5,8,8,u8g_logo_du);
  u8g.setPrintPos(0,45); 
  if(PM==0)                     //判断变量PM返回值 0就显示AM  1就显示PM
  {u8g.print("AM");}
  else
 {u8g.print("PM");}
  u8g.setFont(u8g_font_freedoomr25n); //设定字体(具体请参看 U8GLIB google code页面,大量字体可选)
  u8g.print(hour/10);  
 u8g.print(hour%10);  //输出小时的值
  u8g.print(":");                        //显示一个冒号
  u8g.print(minute/10);    
 u8g.print(minute%10);    //显示分钟的值
  u8g.setFont(u8g_font_freedoomr10r);  //调整显示字体
  u8g.print(":");                         //再显示冒号
  u8g.print(second/10); 
 u8g.print(second%10); 
u8g.setPrintPos(0,60);
u8g.setFont(u8g_font_unifont);
u8g.print("happyday!");
}

我的手机 2017/5/30 14:28:26

void dobutton(void){
if(digitalRead(button)==LOW){ 
  delay(5);
  if(digitalRead(button)==LOW){
  for(int x=0;x   { digitalWrite((x%3)+2,HIGH);
    tone(tonePin,tune[x]);
    delay(580*duration[x]);
    noTone(tonePin);
  digitalWrite((x%3)+2,LOW);}
  delay(100);}}}
江苏科技大学“FlySpiders”本创小组组员学习记录----王澳刚_第1张图片

你可能感兴趣的:(江苏科技大学“FlySpiders”本创小组组员学习记录----王澳刚)