2012年4月20日金曜日

モールス信号練習機

 bounceをsketchして、押しボタン(電鍵の代わり)を押すとブザーが鳴り、同時にLEDが光る。
モールス信号の練習機をブレッドボード上で作成する。


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);
 }
}

ディスプレイの設定

ディスプレイには秋月電子のものを使用した。
ディスプレイ        Arduino
LCD-DB7     14pin    D4
LCD-DB6     13pin    D5  
LCD-DB5     12pin    D6  
LCD-DB4     11pin    D7
LCD-E         6pin    D11
LCD-R/W      5pin
LCD-RS        4pin    D12

LCD-Vo         3pin    potentiometerの中点で端点はGNDと+5v

                    2pin            +5V            
                    1pin            GND            
                  16pin             GND          
                  15pin            +4.2V       抵抗100 ohmを経由する

Sketch


// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
//LiquidCrystal(rs, enable, d4, d5, d6, d7)
LiquidCrystal lcd(12, 11, 7, 6, 5, 4);

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.home();
  lcd.print("Hello, World!");
  lcd.setCursor(0,1);
  lcd.print("JA1NHL");
  lcd.setCursor(10,1);
}

void loop() {
  // Turn off the display:
  lcd.noDisplay();
  delay(500);
   // Turn on the display:
  lcd.display();
  delay(500);
}

/*
  LiquidCrystal Library - display() and noDisplay()

 Demonstrates the use a 16x2 LCD display.  The LiquidCrystal
 library works with all LCD displays that are compatible with the
 Hitachi HD44780 driver. There are many of them out there, and you
 can usually tell them by the 16-pin interface.
  This sketch prints "Hello World!" to the LCD and uses the
 display() and noDisplay() functions to turn on and off
 the display.

 The circuit:
 * LCD RS pin(pin 4) to digital pin 12
 * LCD Enable pin(pin 6) to digital pin 11
 * LCD DB4 pin(pin 11)to digital pin 7
 * LCD DB5 pin(pin 12) to digital pin 6
 * LCD DB6 pin(pin 13) to digital pin 5
 * LCD DB7 pin(pin 14) to digital pin 4
 * LCD R/W pin(pin 5) to ground
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)

 Library originally added 18 Apr 2008
 by David A. Mellis
 library modified 5 Jul 2009
 by Limor Fried (http://www.ladyada.net)
 example added 9 Jul 2009
 by Tom Igoe
 modified 22 Nov 2010
 by Tom Igoe

 This example code is in the public domain.

 http://www.arduino.cc/en/Tutorial/LiquidCrystal
 */



完成すると Hello, World!
JA1NHL 
と表示され、表示が点滅する。