My Arduino Pro Micro arrived today, so I could test all. But I have a few issues.
First the analog input A0 seems to be defective on my Pro Micro so I have to change to A1.
Second my remote controls are not only different in how they look the values that comes from the two wires are different too...
So I have to modify the code from marcb4.
Here is my code:
First the analog input A0 seems to be defective on my Pro Micro so I have to change to A1.
Second my remote controls are not only different in how they look the values that comes from the two wires are different too...
So I have to modify the code from marcb4.
Here is my code:
#include <Keyboard.h>
char F8Key = KEY_F8;
char F7Key = KEY_F7;
int pressed = 0;
void setup() {
Keyboard.begin();
//Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(A1); //Kabel grau | Wire grey
int sensorValue2 = analogRead(A2); //Kabel weiß | Wire white
/*
Serial.print ("A1 = ");
Serial.print (sensorValue);
Serial.print (" | ");
Serial.print ("A2 = ");
Serial.print (sensorValue2);
Serial.print (" | ");
Serial.print ("Pressed = ");
Serial.println (pressed);
*/
delay(50);
if (sensorValue < 800 || sensorValue2 < 800) {
delay(100);
// Fernbedienung 1 | Remute control 1
// GPS
if (sensorValue2 > 180 && sensorValue2 < 240 && pressed == 0) {
Keyboard.print('f');
pressed = 1;
}
// Telefon annehmen | Phone take
if (sensorValue > 240 && sensorValue < 300 && pressed == 0) {
Keyboard.print('p');
pressed = 1;
}
//
// Telefon auflegen | Phone hang up
if (sensorValue2 > 130 && sensorValue2 < 180 && pressed == 0) {
Keyboard.print('o');
pressed = 1;
}
// Sprechen | Speak
if (sensorValue2 > 300 && sensorValue2 < 360 && pressed == 0) {
Keyboard.print('M');
pressed = 1;
}
// Mode
if (sensorValue2 > 60 && sensorValue2 < 120 && pressed == 0) {
//Toggle active application
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press(KEY_F3);
delay(50);
Keyboard.release(KEY_LEFT_CTRL);
Keyboard.release(KEY_F3);
pressed = 1;
}
// Fernbedienung 2 | Remote control 2
// +
if (sensorValue > 470 && sensorValue < 530 && pressed == 0) {
Keyboard.press(F8Key);
delay(100);
Keyboard.releaseAll();
pressed = 1;
}
// -
if (sensorValue > 580 && sensorValue < 640 && pressed == 0) {
Keyboard.press(F7Key);
delay(100);
Keyboard.releaseAll();
pressed = 1;
}
// <
if (sensorValue2 > 530 && sensorValue2 < 590 && pressed == 0) {
Keyboard.print('v');
pressed = 1;
}
// >
if (sensorValue > 410 && sensorValue < 470 && pressed == 0) {
Keyboard.print('n');
pressed = 1;
}
// Mutej
if (sensorValue > 350 && sensorValue < 410 && pressed == 0) {
Keyboard.print('b');
pressed = 1;
}
}
if (sensorValue > 800 && sensorValue2 > 800) {
pressed = 0;
}
}