I need code (sketch) for an arduino uno microcontroller that will be connected t
ID: 3557533 • Letter: I
Question
I need code (sketch) for an arduino uno microcontroller that will be connected to an MT8870 decoder chip. This chip decodes the signal it receives from a phone mic as a dtmf (dual tone multiple frequency) signal. Then the decoder chip translates the tones into digits pressed on the phone. These four signals will be sent in as analog inputs and I need code that I can download on to the microcontroller to take these digits and control a dc motor with pwm that is built in to the arduino uno. For example when I press 1 it turns on at low speed. 2-3-4-5 etc higher speed. And when at higher speed press 5-4-3-2 and it slows down. Also, I would like it to turn of when pressing zero. Please comment all code and explain functionality. I'll rate alot of points for this implementation!!!! It has to work on Arduino uno.
Explanation / Answer
int q_1 = 4;
int q_2 = 5;
int q_3 = 6;
int q_4 = 7;
int red = 8; // 1st device (red LED)
int green = 9; // 2nd device (green LED)
int std_out = 10;
void setup() {
pinMode(q_1, INPUT);
pinMode(q_2, INPUT);
pinMode(q_3, INPUT);
pinMode(q_4, INPUT);
pinMode(std_out, INPUT);
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
}
int getKey () {
int keyVal = 0;
while (digitalRead(std_out) == HIGH); // wait for key to be released
while (digitalRead(std_out) == LOW); // wait for next key press
delay(10); // debounce if needed
keyVal |= digitalRead(q_4) << 3; // depends on HIGH always being defined as 1
keyVal |= digitalRead(q_3) << 2;
keyVal |= digitalRead(q_2) << 1;
keyVal |= digitalRead(q_1);
return keyVal;
}
void loop() {
int keyVal = 0;
// wait a bit...
delay(500);
keyVal = getKey();
switch (keyVal) {
case B1000:
keyVal = getKey();
switch (keyVal) {
case B1101:
digitalWrite(red, HIGH); // turn on 1st device
break;
case B0011:
digitalWrite(red, LOW); // turn off 1st device
break;
}
case B0100:
keyVal = getKey();
switch (keyVal) {
case B1101:
digitalWrite(green, HIGH); // turn on 1st device
break;
case B0011:
digitalWrite(green, LOW); // turn off 1st device
break;
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.