diff --git a/software/DemoBoatyArduino/.vscode/arduino.json b/software/DemoBoatyArduino/.vscode/arduino.json new file mode 100644 index 0000000..6f548f6 --- /dev/null +++ b/software/DemoBoatyArduino/.vscode/arduino.json @@ -0,0 +1,4 @@ +{ + "board": "arduino:avr:uno", + "sketch": "DemoBoatyArduino.ino" +} \ No newline at end of file diff --git a/software/DemoBoatyArduino/.vscode/c_cpp_properties.json b/software/DemoBoatyArduino/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..b6d7f8c --- /dev/null +++ b/software/DemoBoatyArduino/.vscode/c_cpp_properties.json @@ -0,0 +1,32 @@ +{ + "configurations": [ + { + "name": "Win32", + "includePath": [ + "C:\\Program Files (x86)\\Arduino\\tools\\**", + "C:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\**", + "/storage/Shared/Arduino/arduino-1.8.13/hardware/arduino/avr/**", + "/storage/Shared/Arduino/arduino-1.8.13/tools/**" + ], + "forcedInclude": [ + "C:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino\\Arduino.h", + "/storage/Shared/Arduino/arduino-1.8.13/hardware/arduino/avr/cores/arduino/Arduino.h" + ], + "intelliSenseMode": "msvc-x64", + "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.23.28105/bin/Hostx64/x64/cl.exe", + "cStandard": "c11", + "cppStandard": "c++17" + }, + { + "name": "Linux", + "includePath": [ + "/storage/Shared/Arduino/arduino-1.8.13/tools/**", + "/storage/Shared/Arduino/arduino-1.8.13/hardware/arduino/avr/**" + ], + "forcedInclude": [ + "/storage/Shared/Arduino/arduino-1.8.13/hardware/arduino/avr/cores/arduino/Arduino.h" + ] + } + ], + "version": 4 +} \ No newline at end of file diff --git a/software/DemoBoatyArduino/DemoBoatyArduino.ino b/software/DemoBoatyArduino/DemoBoatyArduino.ino new file mode 100644 index 0000000..f998947 --- /dev/null +++ b/software/DemoBoatyArduino/DemoBoatyArduino.ino @@ -0,0 +1,66 @@ +#include +#include +#include +const int FWD_BTN = 2; +const int REV_BTN = 3; +const int SERVO_PWM = 9; +const int ESC_PWM = 10; +const int ADC_VBatt = A0; +const int ADC_POT_0 = A1; +const int ADC_POT_1 = A2; + +Servo esc; +Servo servo; + +static float getBattV() +{ + uint16_t raw = (uint16_t)analogRead(ADC_VBatt); + float vout = (float)raw / 1024.0f * 5.0f; + return (vout * 2.0f); +} + +static float getPot0V() +{ + uint16_t raw = (uint16_t)analogRead(ADC_POT_0); + return (float)raw / 1024.0f * 5.0f; +} + +static float getPot1V() +{ + uint16_t raw = (uint16_t)analogRead(ADC_POT_1); + return (float)raw / 1024.0f * 5.0f; +} + +static void handleMotor() +{ + int val = analogRead(ADC_POT_0); + val = map(val, 0, 1023, 1100, 1900); + esc.writeMicroseconds(val); +} + +static void handleServo() +{ + int val = analogRead(ADC_POT_1); + val = map(val, 0, 1023, 1100, 1900); + servo.writeMicroseconds(val); +} + +void setup() +{ + Serial.begin(9600); + esc.attach(ESC_PWM); + servo.attach(SERVO_PWM); +} + +void loop() +{ + Serial.print("Battery Voltage: "); + Serial.println(getBattV()); + Serial.print("Fwd Pot: "); + Serial.print(getPot0V() / 5.0f * 100.0f); + Serial.println("%"); + Serial.print("Rev Pot: "); + Serial.print(getPot1V() / 5.0f * 100.0f); + Serial.println("%"); + delay(500); +}