Код: Выделить всё
using namespace std;
//set the pins for the button and buzzer
int firstKeyPin = 2;
int secondKeyPin = 3;
int thirdKeyPin = 4;
int fourthKeyPin = 7;
int buzzerPin = 10;
void setup() {
Serial.begin(9600); //start a serial connection with the computer
//set the button pins as inputs
pinMode(firstKeyPin, INPUT_PULLUP);
pinMode(secondKeyPin, INPUT_PULLUP);
pinMode(thirdKeyPin, INPUT_PULLUP);
pinMode(fourthKeyPin, INPUT_PULLUP);
//set the buzzer pin as an output
pinMode(buzzerPin, OUTPUT);
}
void loop() {
auto toneTot = 0b0;
if (digitalRead(firstKeyPin) == LOW) {
tone(buzzerPin, 262); //play the frequency for c
toneTot |= 1;
}
if (digitalRead(secondKeyPin) == LOW) {
tone(buzzerPin, 330); //play the frequency for e
toneTot |= 10;
}
if (digitalRead(thirdKeyPin) == LOW) { //if the third key is pressed
tone(buzzerPin, 392); //play the frequency for g
toneTot |= 100;
}
if (digitalRead(fourthKeyPin) == LOW) { //if the fourth key is pressed
tone(buzzerPin, 494);
toneTot |= 1000;
}
Serial.println("Binary collected");
Serial.println(String(toneTot));
}
Подробнее здесь: https://stackoverflow.com/questions/717 ... ot-working
Мобильная версия