From c45aea471625f80255e85c1b40e55cc874bd1e20 Mon Sep 17 00:00:00 2001 From: angelw22 <23022872+angelw22@users.noreply.github.com> Date: Sun, 18 Aug 2024 08:39:59 -0400 Subject: [PATCH] Create Lesson_6_External_Sensor_Control.ino --- .../Lesson_6_External_Sensor_Control.ino | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 examples/Lesson_6_External_Sensor/Lesson_6_External_Sensor_Control.ino diff --git a/examples/Lesson_6_External_Sensor/Lesson_6_External_Sensor_Control.ino b/examples/Lesson_6_External_Sensor/Lesson_6_External_Sensor_Control.ino new file mode 100644 index 0000000..7b78099 --- /dev/null +++ b/examples/Lesson_6_External_Sensor/Lesson_6_External_Sensor_Control.ino @@ -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 + +#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(); + } +}