Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 25 additions & 27 deletions nerfDrone_client/nerfDrone_client.ino
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ int motorsPin = D1;
int shotPin = D2;
int blastPin = D3;

int motorsState = 0;
int shotState = 0;
int blastState = 0;
bool motorsState = false;
bool shotState = false;
bool blastState = false;

String endpoint = String();

Expand All @@ -24,34 +24,32 @@ void setup()
}

void loop() {

motorsState = digitalRead(motorsPin);
if ( motorsState == HIGH ) {
endpoint = "/motors/on";
request(endpoint);
delay(200);
if (edge(motorsPin, &motorsState)) {
request(motorsState ? "/motors/on" : "/motors/off");
}
if (edge(shotPin, &shotState)) {
if (shotState) {
request("/shotState/on");
}
else {
endpoint = "/motors/off";
request(endpoint);
}
if (edge(blastPin, &blastState)) {
if (blastState) {
request("/blast/on");
}
delay(200);

}
delay(200);
}

void readTriggers() {

shotState = digitalRead(shotPin);
blastState = digitalRead(blastPin);

if (shotState == HIGH) {
endpoint = "/shot";
request(endpoint);
}
if (blastState == HIGH) {
endpoint = "/blast";
request(endpoint);
}
bool edge(int pin, bool *currentState) {
bool pinState = digitalRead(pin);
if ( pinState == HIGH && !currentlyOn ) {
*currentlyOn = true;
return true;
} else if ( pinState == LOW && currentlyOn ) {
*currentlyOn = false;
return true;
}
return false;
}

void initHardware() {
Expand Down