From 2183e465869aa2679279e9744e39754f47ca366a Mon Sep 17 00:00:00 2001 From: tguyenn Date: Mon, 16 Sep 2024 14:27:51 -0500 Subject: [PATCH] Added a bunch of code examples but no idea if they actually work lol --- docs/_sections/_guide-general/forms.md | 2 +- .../getting-started/environment-setup.md | 11 +++--- .../sensors-and-actuators/color-sensors.md | 38 ++++++++++++++++++- .../sensors-and-actuators/ir-sensors.md | 13 ++++++- .../sensors-and-actuators/line-sensors.md | 25 +++++++++++- 5 files changed, 79 insertions(+), 10 deletions(-) diff --git a/docs/_sections/_guide-general/forms.md b/docs/_sections/_guide-general/forms.md index f1ac96bd..0f7cfa7b 100644 --- a/docs/_sections/_guide-general/forms.md +++ b/docs/_sections/_guide-general/forms.md @@ -5,7 +5,7 @@ nav_include: true nav_order: 4 --- -# Forms and Links +# Links and Forms This page contains direct links and forms that you might need for Robotathon! diff --git a/docs/_sections/_guide-primaries/getting-started/environment-setup.md b/docs/_sections/_guide-primaries/getting-started/environment-setup.md index a4539490..69055d66 100644 --- a/docs/_sections/_guide-primaries/getting-started/environment-setup.md +++ b/docs/_sections/_guide-primaries/getting-started/environment-setup.md @@ -21,16 +21,15 @@ Note: While it is good coding practice to leave comments in your code to make it int LED_BUILTIN = 2; // defines the word "LED_BUILTIN" as the number 2 for ease of use when defining and using the pin later void setup() { -pinMode (LED_BUILTIN, OUTPUT); // configures pin 2 to be a GPIO output pin + pinMode(LED_BUILTIN, OUTPUT); // configures pin 2 to be a GPIO output pin } void loop() { -digitalWrite(LED_BUILTIN, HIGH); // writes a digital high to pin 2 -delay(1000); // waits for 1000 milliseconds (1 second) -digitalWrite(LED_BUILTIN, LOW); // writes a digital low to pin 2 -delay(1000); + digitalWrite(LED_BUILTIN, HIGH); // writes a digital high to pin 2 + delay(1000); // waits for 1000 milliseconds (1 second) + digitalWrite(LED_BUILTIN, LOW); // writes a digital low to pin 2 + delay(1000); } - ``` diff --git a/docs/_sections/_guide-primaries/sensors-and-actuators/color-sensors.md b/docs/_sections/_guide-primaries/sensors-and-actuators/color-sensors.md index 166247ab..38b47de4 100644 --- a/docs/_sections/_guide-primaries/sensors-and-actuators/color-sensors.md +++ b/docs/_sections/_guide-primaries/sensors-and-actuators/color-sensors.md @@ -27,7 +27,43 @@ If you want more details on how the color sensor works, check out [this link!](h For this tutorial, we’re only going to be reading the RGB sensor values from the TCS34725. Make sure that your pins are correctly connected or otherwise you won’t receive the data! ```cpp -todo +//Color Sensor headers +#include +#include +#include +//Color sensor definitions +#define APDS9960 INT 2 +#define 120 SDA 21 +#define 12C SCL 22 +#define I2C FREQ 100000 +//Color Sensor unit & 12C unit +Twowire I2C_0 = TwoWire(0); +APDS9960 apds = APDS9960(12C_0, APDS9960_INT); + +void setup() { + //Sets up I2C protocol + I2C_0.begin(I2C_SDA, I2C_SCL, I2C_FREQ); + // Set up color sensor + apds.setInterruptPin (APDS9960_INT); + apds.begin(); + Serial.begin(115200); +} + +void loop() { + int r, g, b, a; + // Wait until color is read from the sensor + while (!apds.colorAvailable()) { delay(5); } + // Read color from sensor apds.readColor(r, g, b, a); + // Print color in decimal + Serial.print("RED: "); + Serial.print(r); + Serial.print(" GREEN: "); + Serial.print(g); + Serial.print(" BLUE: "); + Serial.print(b); + Serial.print(" AMBIENT: "); + Serial.println(a); +} ``` # Tips diff --git a/docs/_sections/_guide-primaries/sensors-and-actuators/ir-sensors.md b/docs/_sections/_guide-primaries/sensors-and-actuators/ir-sensors.md index baefcc83..cb0e85c6 100644 --- a/docs/_sections/_guide-primaries/sensors-and-actuators/ir-sensors.md +++ b/docs/_sections/_guide-primaries/sensors-and-actuators/ir-sensors.md @@ -39,7 +39,18 @@ If you're not sure which ESP32 pins are ADC (Analog to Digital Converter) capabl The following program will allow you to read values from the IR sensor in a loop. After you build and flash the program, you should see the values in your terminal output change as you move it towards and away from an object. ```cpp -todo +#include + +void setup() { + Serial.begin(115200); + ESP32SharpIR IRSensorName(ESP32SharpIR::GP2Y0A21YKOF, 27); + IRSensorName.setFilterRate(0.1f); +} + +void loop() { + Serial.println(IRSensorName.getDistanceFloat()); + delay(500); +} ``` diff --git a/docs/_sections/_guide-primaries/sensors-and-actuators/line-sensors.md b/docs/_sections/_guide-primaries/sensors-and-actuators/line-sensors.md index bfb452d4..551c7c70 100644 --- a/docs/_sections/_guide-primaries/sensors-and-actuators/line-sensors.md +++ b/docs/_sections/_guide-primaries/sensors-and-actuators/line-sensors.md @@ -23,7 +23,30 @@ The following program will allow you to continuously read a general position val different sensors. ```cpp -todo +#include + +QTRSensors qtr; + +void setup { + // set up Serial Communication and sensor pins + Serial.begin(115200); + qtr.setTypeAnalog(); // or setTypeAnalog() + qtr.setSensorPins((const uint8_t[]) {5, 17, 16}, 3); // pin numbers go in the curly brackets {}, and number of pins goes after + + // calibration sequence + for (uint8_t i = 0; i < 250; i++) { + Serial.println("calibrating"); + qtr.calibrate(); + delay(20); + } +} + +void loop() { + uint16_t sensors [3]; + // Get calibrated sensor values returned in the sensors array, along with the // line position, which will range from 0 to 2000, with 1000 corresponding to // a position under the middle sensor. + int16_t position = qtr.readLineBlack (sensors); +} + ``` TIP: always run the calibrate function (i.e. hold a line of the color you’re sensing under all the sensors during set up) to ensure consistent and accurate results.