commit 2b7cea848c261e44f5065aa656ce9cd763859d05 Author: Fenoglio Date: Mon Jul 9 11:18:52 2018 +0200 Initial commit diff --git a/CodeRacerConcept.pptx b/CodeRacerConcept.pptx new file mode 100644 index 0000000..982c3ba Binary files /dev/null and b/CodeRacerConcept.pptx differ diff --git a/coderace3.pdf b/coderace3.pdf new file mode 100644 index 0000000..8ecdd24 Binary files /dev/null and b/coderace3.pdf differ diff --git a/coderacer.fzz b/coderacer.fzz new file mode 100644 index 0000000..d0bd3f2 Binary files /dev/null and b/coderacer.fzz differ diff --git a/coderacer.odp b/coderacer.odp new file mode 100644 index 0000000..af31745 Binary files /dev/null and b/coderacer.odp differ diff --git a/coderacer_motor.fzz b/coderacer_motor.fzz new file mode 100644 index 0000000..6101b58 Binary files /dev/null and b/coderacer_motor.fzz differ diff --git a/coderacercode.ppt b/coderacercode.ppt new file mode 100644 index 0000000..9d7b255 Binary files /dev/null and b/coderacercode.ppt differ diff --git a/esp32_motor/esp32_motor.ino b/esp32_motor/esp32_motor.ino new file mode 100644 index 0000000..1f059c6 --- /dev/null +++ b/esp32_motor/esp32_motor.ino @@ -0,0 +1,37 @@ +#define MOTOR_SPEED 27 +#define MOTOR_FWRD 26 +#define MOTOR_BACK 25 +#define MAX_SPEED 0xffff +#include "esp32-hal-ledc.h" + +void setup() { + // put your setup code here, to run once: + pinMode(MOTOR_FWRD,OUTPUT); + pinMode(MOTOR_BACK,OUTPUT); + + digitalWrite(MOTOR_BACK,LOW); + digitalWrite(MOTOR_FWRD,HIGH); + + //for motor ... + ledcSetup(1, 5000, 8); // channel 1, 50 Hz, 16-bit width + ledcAttachPin(MOTOR_SPEED, 1); // GPIO 22 assigned to channel 1 + analogWrite(MOTOR_SPEED, 0); + + Serial.begin(115200); + Serial.println("Enter values between 0 - 255"); +} + +void loop() { + + if(Serial.available()) + { + uint8_t speed = Serial.parseInt(); + Serial.println(speed); + analogWrite(MOTOR_SPEED, speed ); + } +} + +void analogWrite(uint8_t pin, uint8_t speed){ + ledcWrite(1, speed); +} + diff --git a/esp32_servo/esp32_servo.ino b/esp32_servo/esp32_servo.ino new file mode 100644 index 0000000..3aa29e3 --- /dev/null +++ b/esp32_servo/esp32_servo.ino @@ -0,0 +1,24 @@ +#include + +Servo myservo; // create servo object to control a servo +int servo_angle = 0; // variable to store the servo position +#define SERVOPIN 14 // Recommended PWM GPIO pins on the ESP32 include 2,4,12-19,21-23,25-27,32-33 + +void setup() { + // put your setup code here, to run once: + myservo.attach(SERVOPIN); // attaches the servo on pin 18 to the servo object + // using default min/max of 1000us and 2000us + // different servos may require different min/max settings + // for an accurate 0 to 180 sweep +} + +void loop() { + for (servo_angle = 0; servo_angle <= 180; servo_angle += 10) { // goes from 0 degrees to 180 degrees in steps of 1 degree + myservo.write(servo_angle); // tell servo to go to position in variable 'pos' + delay(50); // waits 15ms for the servo to reach the position + } + for (servo_angle = 180; servo_angle >= 0; servo_angle -= 10) { // goes from 180 degrees to 0 degrees + myservo.write(servo_angle); // tell servo to go to position in variable 'pos' + delay(50); // waits 15ms for the servo to reach the position + } +} diff --git a/esp32_servo_sonic/esp32_servo_sonic.ino b/esp32_servo_sonic/esp32_servo_sonic.ino new file mode 100644 index 0000000..dda472e --- /dev/null +++ b/esp32_servo_sonic/esp32_servo_sonic.ino @@ -0,0 +1,105 @@ +#include + +Servo myservo; // create servo object to control a servo +int servo_angle = 0; // variable to store the servo position +#define SERVOPIN 14 // Recommended PWM GPIO pins on the ESP32 include 2,4,12-19,21-23,25-27,32-33 +#define SERVO_LEFT 45 +#define SERVO_RIGHT 135 +#define SERVO_FORWARD 90 + + +#define US_TRIG 13 +#define US_ECHO 12 +#define US_STOP_DISTANCE 10 +long distance_forward_cm,distance_left_cm,distance_right_cm; + + +void setup() { + //Serial port + Serial.begin(115200); + + //Ultra sonic pins + pinMode(US_TRIG, OUTPUT); + pinMode(US_ECHO, INPUT); + //servo init + myservo.attach(SERVOPIN); // attaches the servo on pin 18 to the servo object + // using default min/max of 1000us and 2000us + // different servos may require different min/max settings + // for an accurate 0 to 180 sweep + delay(1000); + myservo.write(SERVO_FORWARD); // start looking forward + delay(2000); + myservo.write(SERVO_LEFT); // start looking forward + delay(2000); + myservo.write(SERVO_FORWARD); // start looking forward + delay(2000); + myservo.write(SERVO_RIGHT); // start looking forward + delay(2000); + myservo.write(SERVO_FORWARD); // start looking forward + +} + + +void loop() { + + distance_forward_cm = measure_distance_cm(); // measure the distance in front of us + + if(distance_forward_cm distance_right_cm){ + // goto to the left + for(int pos = SERVO_FORWARD;pos>SERVO_LEFT;pos--){ + myservo.write(pos); + delay(15); + } + } + else{ + // goto to the right + for(int pos = SERVO_FORWARD;pos