#include <HID.h>
#include <HID-Settings.h>
#include <HID-Project.h>
#include <CapacitiveSensor.h>
const int led1 = 6;
const int led2 = 8;
const int led3 = 9;
bool buttonPressed1 = false;
bool buttonPressed2 = false;
bool buttonPressed3 = false;
int firstPress1 = 0;
int firstPress2 = 0;
int firstPress3 = 0;
bool screenCase = true;
CapacitiveSensor cs_13_A0 = CapacitiveSensor(13, A0);
CapacitiveSensor cs_5_A1 = CapacitiveSensor(5, A1);
CapacitiveSensor cs_10_A2 = CapacitiveSensor(10, A2);
void setup()
{
Consumer.begin();
System.begin();
Keyboard.begin();
pinMode(13, OUTPUT);
pinMode(10, OUTPUT);
pinMode(5, OUTPUT);
pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);
}
void loop()
{
long start = millis();
long total1 = cs_13_A0.capacitiveSensor(30);
long total2 = cs_5_A1.capacitiveSensor(30);
long total3 = cs_10_A2.capacitiveSensor(30);
if (total1 > 100) { digitalWrite(led1, HIGH); }
else { digitalWrite(led3, LOW); }
if (total2 > 100) { digitalWrite(led2, HIGH); }
else { digitalWrite(led2, LOW); }
if (total3 > 100) { digitalWrite(led3, HIGH); }
else { digitalWrite(led1, LOW); }
int time = millis();
if (total3 > 100 && buttonPressed1 == false) {
firstPress1 = millis();
buttonPressed1 = true;
}
if (total3 < 50 && buttonPressed1 == true) {
if (time - firstPress1 > 50) {
Consumer.write(MEDIA_VOL_UP);
}
buttonPressed1 = false;
}
time = millis();
if (total2 > 100 && buttonPressed2 == false) {
firstPress2 = millis();
buttonPressed2 = true;
}
if (total2 < 50 && buttonPressed2 == true) {
if (time - firstPress2 > 50) {
if (screenCase == true) {
System.write(SYSTEM_SLEEP);
screenCase = false;
} else if (screenCase == false) {
Keyboard.write(CONSUMER_POWER);
screenCase = true;
}
}
buttonPressed2 = false;
}
time = millis();
if (total1 > 100 && buttonPressed3 == false) {
firstPress3 = millis();
buttonPressed3 = true;
}
if (total1 < 50 && buttonPressed3 == true) {
if (time - firstPress3 > 50) {
Consumer.write(MEDIA_VOL_DOWN);
}
buttonPressed3 = false;
}
}
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.