Controller Photo
Schematic Photo
Code
// Team 7
// Donovan Peckham
// Timothy Williams
#include <Adafruit_CircuitPlayground.h>
#include <Adafruit_Circuit_Playground.h>
#include <Keyboard.h>
#include <KeyboardLayout.h>
#include <Keyboard_da_DK.h>
#include <Keyboard_de_DE.h>
#include <Keyboard_es_ES.h>
#include <Keyboard_fr_FR.h>
#include <Keyboard_hu_HU.h>
#include <Keyboard_it_IT.h>
#include <Keyboard_pt_PT.h>
#include <Keyboard_sv_SE.h>
#define trigPin 9
#define echoPin 6
const int LEDpin = 13;
const int switchPinUp = A6;
const int switchPinDown = A4;
const int Right = KEY_RIGHT_ARROW;
const int Left = KEY_LEFT_ARROW;
const int Up = KEY_UP_ARROW;
const int Down = KEY_DOWN_ARROW;
const int Z = 122;
const int X = 120;
int potPin = A0;
int sensorValue;
void setup() {
pinMode(LEDpin, OUTPUT);
pinMode(switchPinUp, INPUT);
pinMode(switchPinDown, INPUT);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
while(!Serial);
Keyboard.begin();
}
void loop() {
// Potentiometer for Left and Right Movement
sensorValue = analogRead(potPin);
Serial.println(sensorValue);
delay(10);
if (sensorValue > 700) {
Keyboard.press(Left);
}
if (sensorValue < 300) {
Keyboard.press(Right);
}
if (sensorValue > 300 && sensorValue < 700) {
Keyboard.release(Left);
Keyboard.release(Right);
}
// Switches for Up and Down Movement
int switchStateUp = analogRead(switchPinUp);
int switchStateDown = analogRead(switchPinDown);
Serial.println(switchStateUp);
Serial.println(switchStateDown);
if (switchStateUp < 50) {
Keyboard.press(Up);
}
if (switchStateUp > 100) {
Keyboard.release(Up);
}
if (switchStateDown < 50) {
Keyboard.press(Down);
}
if (switchStateDown > 100) {
Keyboard.release(Down);
}
// Ultrasonic Range Sensor for Powerup Activation
long duration, distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
if (distance < 10) {
digitalWrite(LEDpin, HIGH);
Keyboard.press(Z);
} else {
digitalWrite(LEDpin, LOW);
Keyboard.release(Z);
}
if (distance >= 400 || distance <= 0) {
Serial.println("Out of range");
} else {
Serial.print(distance);
Serial.println(" cm");
}
delay(500);
// Light Sensor for Bomb Placement
int light = analogRead(A8);
Serial.print("\t");
Serial.println(light);
if (light > 4) {
Keyboard.press(X);
}
if (light <= 1) {
Keyboard.release(X);
}
}
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.