Skip to content

Commit

Permalink
Added a bunch of code examples but no idea if they actually work lol
Browse files Browse the repository at this point in the history
  • Loading branch information
tguyenn committed Sep 16, 2024
1 parent ba71c7c commit 2183e46
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/_sections/_guide-general/forms.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

```


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Wire.h>
#include <Arduino APDS9960.h>
#include <bits/stdc++.h>
//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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <ESP32SharpIR.h>

void setup() {
Serial.begin(115200);
ESP32SharpIR IRSensorName(ESP32SharpIR::GP2Y0A21YKOF, 27);
IRSensorName.setFilterRate(0.1f);
}

void loop() {
Serial.println(IRSensorName.getDistanceFloat());
delay(500);
}
```


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,30 @@ The following program will allow you to continuously read a general position val
different sensors.

```cpp
todo
#include <QTRSensors.h>

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.
Expand Down

0 comments on commit 2183e46

Please sign in to comment.