-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from angelw22/add-new-external-sensor-control
Create Lesson_6_External_Sensor_Control.ino
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
examples/Lesson_6_External_Sensor/Lesson_6_External_Sensor_Control.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Programmable-Air | ||
// Author: angelw | ||
// https://github.com/orgs/Programmable-Air | ||
// | ||
// This example uses an IR sensor to control when to suck, blow and vent using the Programmable Air. | ||
// | ||
// PCB v0.3/v0.4/v0.5 | ||
|
||
#include "programmable_air.h" | ||
#include <SharpIR.h> | ||
|
||
#define DEBUG 1 | ||
|
||
#define BLOWING_DIST 45 | ||
#define SUCKING_DIST 70 | ||
|
||
int distance; | ||
|
||
//Check and edit the sensor model when necessary, models supported by library: GP2Y0A41SK0F, GP2Y0A21YK0F, GP2Y0A02YK0F. https://github.com/qub1750ul/Arduino_SharpIR | ||
SharpIR sensor( SharpIR::GP2Y0A21YK0F, A0); | ||
|
||
void setup() { | ||
initializePins(); | ||
pinMode(A0, INPUT); | ||
} | ||
|
||
void loop() { | ||
int distance = sensor.getDistance(); | ||
Serial.println( distance ); | ||
|
||
if (distance > SUCKING_DIST) { | ||
switchOffPumps(); | ||
switchOnPump(1, 50); | ||
suck(); | ||
//Serial.println("sucking"); | ||
} else if (distance > BLOWING_DIST) { | ||
switchOffPumps(); | ||
switchOnPump(2); | ||
blow(); | ||
//Serial.println("blowing"); | ||
} else { | ||
switchOffPumps(); | ||
vent(); | ||
} | ||
} |