From 17c99f67332d4919fa2e71291031891addac60f9 Mon Sep 17 00:00:00 2001 From: Toby Nguyen Date: Tue, 17 Sep 2024 15:48:40 -0500 Subject: [PATCH] Fixed code snippets to work out of the box --- .../sensors-and-actuators/actuators.md | 14 +++++++- .../sensors-and-actuators/color-sensors.md | 33 +++++++++++-------- .../sensors-and-actuators/ir-sensors.md | 6 ++++ .../sensors-and-actuators/line-sensors.md | 8 ++++- 4 files changed, 46 insertions(+), 15 deletions(-) diff --git a/docs/_sections/_guide-primaries/sensors-and-actuators/actuators.md b/docs/_sections/_guide-primaries/sensors-and-actuators/actuators.md index 2e515453..fc81158e 100644 --- a/docs/_sections/_guide-primaries/sensors-and-actuators/actuators.md +++ b/docs/_sections/_guide-primaries/sensors-and-actuators/actuators.md @@ -46,6 +46,12 @@ Control Pins: Connect the control pins (e.g., IN1, IN2, ENA) on the motor contro The following is an example of configuring and running the motor in software: ```cpp +#include "sdkconfig.h" +#ifndef CONFIG_BLUEPAD32_PLATFORM_ARDUINO +#error "Must only be compiled when using Bluepad32 Arduino platform" +#endif // !CONFIG_BLUEPAD32_PLATFORM_ARDUINO +#include + #define IN1 27 // Control pin 1 #define IN2 26 // Control pin 2 #define ENA 25 // PWM pin @@ -99,7 +105,13 @@ If you're not sure which ESP32 pins are PWM capable, then check out the diagram In this competition, we will be using the Arduino servo library to control the servos. The following is an example of how to configure the servo: ```cpp -#include +#include "sdkconfig.h" +#ifndef CONFIG_BLUEPAD32_PLATFORM_ARDUINO +#error "Must only be compiled when using Bluepad32 Arduino platform" +#endif // !CONFIG_BLUEPAD32_PLATFORM_ARDUINO +#include + +#include Servo myservo; 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 38b47de4..0266dcce 100644 --- a/docs/_sections/_guide-primaries/sensors-and-actuators/color-sensors.md +++ b/docs/_sections/_guide-primaries/sensors-and-actuators/color-sensors.md @@ -27,24 +27,31 @@ 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 -//Color Sensor headers +#include "sdkconfig.h" +#ifndef CONFIG_BLUEPAD32_PLATFORM_ARDUINO +#error "Must only be compiled when using Bluepad32 Arduino platform" +#endif // !CONFIG_BLUEPAD32_PLATFORM_ARDUINO +#include + + #include -#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); + +#define APDS9960_INT 2 +#define I2C_SDA 21 +#define I2C_SCL 22 +#define I2C_FREQ 100000 + +TwoWire I2C_0 = TwoWire(0); +APDS9960 apds = APDS9960(I2C_0, APDS9960_INT); void setup() { - //Sets up I2C protocol + //sets up I2C protocol I2C_0.begin(I2C_SDA, I2C_SCL, I2C_FREQ); - // Set up color sensor - apds.setInterruptPin (APDS9960_INT); + + //sets up color sensor + apds.setInterruptPin(APDS9960_INT); apds.begin(); Serial.begin(115200); } 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 cb0e85c6..3fea76a0 100644 --- a/docs/_sections/_guide-primaries/sensors-and-actuators/ir-sensors.md +++ b/docs/_sections/_guide-primaries/sensors-and-actuators/ir-sensors.md @@ -39,6 +39,12 @@ 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 +#include "sdkconfig.h" +#ifndef CONFIG_BLUEPAD32_PLATFORM_ARDUINO +#error "Must only be compiled when using Bluepad32 Arduino platform" +#endif // !CONFIG_BLUEPAD32_PLATFORM_ARDUINO +#include + #include void setup() { 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 551c7c70..94cbb7e5 100644 --- a/docs/_sections/_guide-primaries/sensors-and-actuators/line-sensors.md +++ b/docs/_sections/_guide-primaries/sensors-and-actuators/line-sensors.md @@ -23,11 +23,17 @@ The following program will allow you to continuously read a general position val different sensors. ```cpp +#include "sdkconfig.h" +#ifndef CONFIG_BLUEPAD32_PLATFORM_ARDUINO +#error "Must only be compiled when using Bluepad32 Arduino platform" +#endif // !CONFIG_BLUEPAD32_PLATFORM_ARDUINO +#include + #include QTRSensors qtr; -void setup { +void setup() { // set up Serial Communication and sensor pins Serial.begin(115200); qtr.setTypeAnalog(); // or setTypeAnalog()