分享

LCD+LED+蜂鳴器

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4); /
#define NOTE_D0 -1
#define NOTE_D1 294
#define NOTE_D2 330
#define NOTE_D3 350
#define NOTE_D4 393
#define NOTE_D5 441
#define NOTE_D6 495
#define NOTE_D7 556
#define NOTE_DL1 147
#define NOTE_DL2 165
#define NOTE_DL3 175
#define NOTE_DL4 196
#define NOTE_DL5 221
#define NOTE_DL6 248
#define NOTE_DL7 278
#define NOTE_DH1 589
#define NOTE_DH2 661
#define NOTE_DH3 700
#define NOTE_DH4 786
#define NOTE_DH5 882
#define NOTE_DH6 990
#define NOTE_DH7 112  
#define WHOLE 1
#define HALF 0.5
#define QUARTER 0.25
#define EIGHTH 0.25
#define SIXTEENTH 0.625  
int tune[] =  
{  
NOTE_D0,NOTE_D0,NOTE_D0,NOTE_D6,NOTE_D7,NOTE_DH1,NOTE_D7,NOTE_DH1,NOTE_DH3,NOTE_D7,NOTE_D7,NOTE_D7,NOTE_D3,NOTE_D3,
NOTE_D6,NOTE_D5,NOTE_D6,NOTE_DH1,NOTE_D5,NOTE_D5,NOTE_D5,NOTE_D3,NOTE_D4,NOTE_D3,NOTE_D4,NOTE_DH1,
NOTE_D3,NOTE_D3,NOTE_D0,NOTE_DH1,NOTE_DH1,NOTE_DH1,NOTE_D7,NOTE_D4,NOTE_D4,NOTE_D7,NOTE_D7,NOTE_D7,NOTE_D0,NOTE_D6,NOTE_D7,
NOTE_DH1,NOTE_D7,NOTE_DH1,NOTE_DH3,NOTE_D7,NOTE_D7,NOTE_D7,NOTE_D3,NOTE_D3,NOTE_D6,NOTE_D5,NOTE_D6,NOTE_DH1,
NOTE_D5,NOTE_D5,NOTE_D5,NOTE_D2,NOTE_D3,NOTE_D4,NOTE_DH1,NOTE_D7,NOTE_D7,NOTE_DH1,NOTE_DH1,NOTE_DH2,NOTE_DH2,NOTE_DH3,NOTE_DH1,NOTE_DH1,NOTE_DH1,
NOTE_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1,0.5,0.5,    1+0.5,0.5,1,1,
 1,1,1,0.5,0.5,    1.5,0.5,1,1,    1,1,1,1,
 0.5,0.5,1,1,0.5,0.5,    1.5,0.25,0.5,1,    1,1,1,1,
 1,1,1,1,    1,1,1,1,    0.5,0.5,1,1,0.5,0.5,
 1,0.5,0.5,1,1,    1,1,1,1,    1,1,1,1,
 0.5,0.5,1,1,0.5,0.5,    1,0.5,0.25,0.5,1,    1,1,1,0.5,0.5
};
int length;
int tonePin=3;
int del = 100; 
void setup()
{  
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
 pinMode(tonePin,OUTPUT);
 pinMode(6, INPUT);
 length = sizeof(tune)/sizeof(tune[0]);符
lcd.init(); // initialize the lcd
lcd.init();
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("Castle in the ");
lcd.setCursor(0,1);
lcd.print("Sky-By Riley  ");
}
void loop()
{  
digitalWrite(9, HIGH);
delay(del);
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
delay(del);
digitalWrite(10, LOW);
digitalWrite(11, HIGH);
delay(del);
digitalWrite(11, LOW);
digitalWrite(12, HIGH);
delay(del);
digitalWrite(12, LOW);
digitalWrite(13, HIGH);
delay(del);
digitalWrite(13, LOW);
 for(int x=0;x<length;x++)
 {  
   tone(tonePin,tune[x]);
delay(400*duration[x]);
noTone(tonePin);
 }
 delay(5000);
}
分類:親子

評論
上一篇
  • 下一篇
  • 更多文章
    載入中... 沒有更多了