モールス信号の練習機をブレッドボード上で作成する。
Sketch
/* bounce
内部プルアップ抵抗20 kohmを有効にする
The circuit:
LED attached from pin 13 to ground
This code turns a led on/off through a debounced button(keyingPin)
*/
#include <Bounce.h>
int buzzerPin=10;
int ledPin=13;
int keyingPin=19;
// Instantiate a Bounce object with a 5 millisecond debounce time
Bounce bouncer = Bounce( keyingPin,5 );
void setup() {
pinMode(buzzerPin, OUTPUT); // sets the pin as output
pinMode(keyingPin,INPUT); // sets the pin as input
pinMode(ledPin,OUTPUT); // sets the pin as output
digitalWrite(keyingPin,HIGH);
}
void loop() {
bouncer.update ( ); // Update the debouncer
int value = bouncer.read(); // Get the update value
if ( value == LOW) { // Turn on or off the LED
digitalWrite(ledPin, HIGH );
analogWrite(buzzerPin,128);
} else {
digitalWrite(ledPin, LOW );
analogWrite(buzzerPin, 0);
}
}
0 件のコメント:
コメントを投稿