/////////////////////////////////
// ShellShock //
// Custom Controller //
////////////////////////////////
#include <Keyboard.h>
#include <Adafruit_Circuit_Playground.h>
#include <Adafruit_CircuitPlayground.h>
const int debounce = 100;
const int threshold = 500;
void setup()
{
CircuitPlayground.begin();
pinMode(CPLAY_SLIDESWITCHPIN, INPUT_PULLUP);
pinMode(CPLAY_LEFTBUTTON, INPUT_PULLDOWN); //button A
pinMode(CPLAY_RIGHTBUTTON, INPUT_PULLDOWN); //button B
Keyboard.begin();
}
void loop()
{
//Turns controller on and off
if(CircuitPlayground.readCap(A3) > threshold && digitalRead(CPLAY_SLIDESWITCHPIN))
{
Keyboard.write(' ');
delay(debounce);
}
//Potentiometer controlls angle of tank barrel
int pot = analogRead(A4);
if(pot > 200 && pot < 400)
{
Keyboard.write('KEY_UP_ARROW');
delay(debounce);
}
else if(pot > 400 && pot < 600)
{
Keyboard.write('KEY_DOWN_ARROW');
delay(debounce);
}
//Slide potentiometer controlls tank movement
int pot = analogRead(A6);
if(pot > 200 && pot < 400)
{
Keyboard.write('D');
delay(debounce);
}
else if(pot > 400 && pot < 600)
{
Keyboard.write('A');
delay(debounce);
}
//Slide potentiometer controlls power of shot
int pot = analogRead(A2);
if(pot > 200 && pot < 400)
{
Keyboard.write('KEY_RIGHT_ARROW');
delay(debounce);
}
else if(pot > 400 && pot < 600)
{
Keyboard.write('KEY_LEFT_ARROW');
delay(debounce);
}
Serial.print(CircuitPlayground.readCap(A3));
Serial.print("\t");
Serial.println(analogRead(A2));
Serial.println(analogRead(A6));
}
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.