Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions components/arduino/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ set(LIBRARY_SRCS
libraries/QTRSensors/src/QTRSensors.cpp
libraries/ESP32-SharpIR/src/ESP32SharpIR.cpp
libraries/ESP32Servo/src/ESP32Servo.cpp
libraries/ESP32Servo/src/ESP32PWM.cpp
libraries/ArduinoOTA/src/ArduinoOTA.cpp
libraries/AsyncUDP/src/AsyncUDP.cpp
libraries/BluetoothSerial/src/BluetoothSerial.cpp
Expand Down
2 changes: 1 addition & 1 deletion main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ set(srcs

set(requires "bluepad32" "bluepad32_arduino" "arduino" "btstack" "callbacks")

idf_component_register(SRCS "${srcs}"
idf_component_register(SRCS "servo.cpp" "lineReader.cpp" "${srcs}"
INCLUDE_DIRS "."
REQUIRES "${requires}")
25 changes: 25 additions & 0 deletions main/arduino_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <Bluepad32.h>
#include <uni.h>
#include "controller_callbacks.h"
#include <ESP32Servo.h>

extern ControllerPtr myControllers[BP32_MAX_GAMEPADS]; // BP32 library allows for up to 4 concurrent controller connections, but we only need 1

Expand All @@ -29,11 +30,35 @@ void dumpGamepad(ControllerPtr ctl) {
);
}

int IN1=16;
int IN2=17;

Servo myServo;

void setup() {
BP32.setup(&onConnectedController, &onDisconnectedController);
BP32.forgetBluetoothKeys();
esp_log_level_set("gpio", ESP_LOG_ERROR); // Suppress info log spam from gpio_isr_service
uni_bt_allowlist_set_enabled(true);

Serial.begin(115200);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);

// Spin motor
digitalWrite(IN1, HIGH); // PWM signal
digitalWrite(IN2, LOW); // Direction control

delay(1000); // Run for 1 second

// Stop motor
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);

delay(1000); // Stop for 1 second

vTaskDelay(1); // Yield CPU to not starve other ESP32 processes and cause WDT reset

}

void loop() {
Expand Down
29 changes: 29 additions & 0 deletions main/lineReader.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "sdkconfig.h"
#include <Arduino.h>

#include <QTRSensors.h>

HardwareSerial &Console = Serial;

QTRSensors qtr;
uint16_t sensors[2];

void setup() {
// set up Serial Communication and sensor pins
Serial.begin(115200);
qtr.setTypeAnalog(); // or setTypeAnalog()
qtr.setSensorPins((const uint8_t[]) {32, 33}, 2); // pin numbers go in the curly brackets {}, and number of sensors in use goes after

// calibration sequence
for (uint8_t i = 0; i < 250; i++) {
Console.printf("calibrating %d/250\n", i); // 250 is the number of calibrations recommended by manufacturer
qtr.calibrate();
delay(20);
}
}

void loop() {
qtr.readLineBlack(sensors); // Get calibrated sensor values returned into sensors[]
Console.printf("S1: %d S2: %d\n", sensors[0], sensors[1]);
delay(250);
}
20 changes: 20 additions & 0 deletions main/servo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
include "sdkconfig.h"
include <Arduino.h>

include <ESP32Servo.h>

Servo myServo;

void setup() {
myServo.attach(12);
myServo.write(0); // Rotate to 0 degrees
delay(1000); // Delay 1000 ms
myServo.write(180); // Rotate to 180 degrees
delay(1000);

vTaskDelay(1); // Yield CPU to not starve other ESP32 processes and cause WDT reset

}

void loop() {
}