วันศุกร์ที่ 28 กันยายน พ.ศ. 2561

งานในชั้นเรียนที่ 8 Buzzer แสดงผลที่จอ LED 7-Segmen

งานในชั้นเรียนที่ 8 Buzzer แสดงผลที่จอ LED 7-Segmen




CODE1
#include "LedControl.h"
#define C4  262
#define D4  294
#define E4  330
#define F4  349
#define FS4 370
#define G4  392
#define A4  440
#define B4  494
#define C5  523
#define D5  587

int melody[] = {C4,D4,E4,F4,G4,A4,B4,C5};
float beats[] = {1,1,1,1,1,1,1,1};

int buzzer = 11;
int timestop = 70;

LedControl lc=LedControl(8,10,9,1);

void setup() {

lc.shutdown(0,false);
lc.setIntensity(0,5);
lc.clearDisplay(0);
int dl = 500;
pinMode(buzzer, OUTPUT);
int numnote;
numnote = sizeof(melody)/2;
for(int i=0;i<numnote;i++){
  lc.setChar(0,7-i,'-',false);
  tone(buzzer, melody[i],dl*beats[i]);
  delay(dl*beats[i]);
  digitalWrite(buzzer, HIGH);
  delay(timestop);
}
}

void loop() {
  // put your main code here, to run repeatedly:

}

CODE2
#include "LedControl.h"
#define C4  262
#define D4  294
#define E4  330
#define F4  349
#define FS4 370
#define G4  392
#define A4  440
#define B4  494
#define C5  523
#define D5  587

int melody[] = {D4,D4,E4,D4,G4,FS4,D4,D4,E4,D4,A4,G4,D4,D4,D5
,B4,G4,FS4,E4,C5,C5,B4,G4,A4,G4};
float beats[] = {0.5,0.5,1,1,1,2,0.5,0.5,1,1,1,2,0.5,0.5,1,1,1,1,1,0.5,0.5,1,1,1,2,};

int buzzer = 11;
int timestop = 70;

LedControl lc=LedControl(8,10,9,1);
// Pin 8->DIN, 10->CLK, 9->CS(LOAD),

void setup() {

lc.shutdown(0,false);
lc.setIntensity(0,5);
lc.clearDisplay(0);
int dl = 400;
pinMode(buzzer, OUTPUT);
lc.setChar(0,7,'H',false);
lc.setChar(0,6,'b',false);
lc.setChar(0,5,'d',false);
int numnote;
numnote = sizeof(melody)/2;
for(int i=0;i<numnote;i++){

  tone(buzzer, melody[i],dl*beats[i]);
  delay(dl*beats[i]);
  digitalWrite(buzzer, HIGH);
  delay(timestop);
}
}

void loop() {
  // put your main code here, to run repeatedly:

}

CODE3
#include "LedControl.h"
#define C4  262
#define D4  294
#define E4  330
#define F4  349
#define G4  392

int melody[] = {E4,D4,C4,D4,E4,E4,E4,D4,D4,D4,E4,G4,G4,E4,D4
,C4,D4,E4,E4,E4,D4,D4,E4,D4,C4};
float beats[] = {1,1,1,1,1,1,2,1,1,2,1,1,2,1,1,1,1,1,1,2,1,1,1,1,4,};

int buzzer = 11;
int timestop = 70;

LedControl lc=LedControl(8,10,9,1);
// Pin 8->DIN, 10->CLK, 9->CS(LOAD),

void setup() {

lc.shutdown(0,false);
lc.setIntensity(0,5);
lc.clearDisplay(0);
int dl = 250;
pinMode(buzzer, OUTPUT);
int numnote;
numnote = sizeof(melody)/2;
for(int i=0;i<numnote;i++){
  lc.setDigit(0,0,beats[i],false);
  tone(buzzer, melody[i],dl*beats[i]);
  delay(dl*beats[i]);
  digitalWrite(buzzer, HIGH);
  delay(timestop);
    }
    delay(500);
 
  lc.setChar(0,0,16,false);
}
int dly = 100;
void loop() {

  lc.setChar(0,0,1,false);
delay(dly);
 lc.setChar(0,0,2,false);
delay(dly);
 lc.setChar(0,0,3,false);
delay(dly);
 lc.setChar(0,0,4,false);
delay(dly);
 lc.setChar(0,0,5,false);
delay(dly);
 lc.setChar(0,0,6,false);
delay(dly);
 lc.setChar(0,0,7,false);
delay(dly);
 lc.setChar(0,0,8,false);
delay(dly);
}

ไม่มีความคิดเห็น:

แสดงความคิดเห็น