Data Sheet
4/27/2018 OpenCR1.0
http://emanual.robotis.com/docs/en/parts/controller/opencr10/ 32/50
OpenCR has a built-in BUZZER, and the sound varies depending on the frequency. The built-
in BUZZER is also mapped to the arduino pin number, and the arduino pin number is as
follows. Arduino’s Tone function is ported, so you can use BUZZER by using this function.
It outputs the melody according to the scale defined in the pitches.h header. The following
code is a change from OpenCR’s BUZZER to only the PIN number in the example provided
in the Arduino IDE.
7. 3. 2. Result
OpenCR Arduino Test - BUZZER
7. 4. PWM
This is the PWM output test from the Arundin pin of the OpenCR board.
7. 4. 1. Code
OpenCR has the same pin configuration as Arduino Uno. The PWM output is also mapped
to the same port. Therefore, analogueWrite is used to output the PWM duty ratio to the
corresponding ports. The resolution is 8 bits, from 0 to 255, and the frequency is 50 KHz.
#define BDPIN_BUZZER 31
#include "pitches.h"
// notes in the melody:
int melody[] = {
NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4
};
// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
4, 8, 8, 4, 4, 4, 4, 4
};
void setup() {
// iterate over the notes of the melody:
for (int thisNote = 0; thisNote < 8; thisNote++) {
// to calculate the note duration, take one second
// divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 1000 / noteDurations[thisNote];
tone(BDPIN_BUZZER, melody[thisNote], noteDuration);
// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
// stop the tone playing:
noTone(BDPIN_BUZZER);
}
}
OpenCR1.0
Back to Top ▲