Commit affffea0 authored by Ondřej Kučera's avatar Ondřej Kučera

button now calibrates wheels

parent 569a2442
......@@ -4,6 +4,7 @@
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>
#include <Adafruit_SSD1306.h>
#include <EEPROM.h>
//radio
#define NETWORKID 5 // Must be the same for all nodes (0 to 255)
......@@ -22,11 +23,6 @@
#define SW 7
#define STALIN A0
//steering bounds
#define STRAIGHT 50
#define FULL_LEFT 20
#define FULL_RIGHT 90
//ultrasound
#define ECHO 11
#define TRIG 12
......@@ -44,12 +40,23 @@ RFM69 radio(CHIP_SELECT_PIN, INTERUP_PIN, true); //radio
Servo servo; //steering servo
Adafruit_BMP280 bmp; //temperature sensor
//steering bounds
/*
int STRAIGHT = 50;
int FULL_LEFT = STRAIGHT-30;
int FULL_RIGHT = STRAIGHT+40;
*/
int STRAIGHT;
int FULL_LEFT;
int FULL_RIGHT;
// main speed and steer vars
int SPEED = 0; // 0 - 255
int STEER = STRAIGHT; // 0 - 255
int speedNum = 0; // -5 - 5
int steerNum = 0; // -5 - 5
bool BUTTON = false;
bool _BUTTON = false;
// vars for monitoring change
int _SPEED = 1;
......@@ -89,6 +96,12 @@ typedef struct {
// -------------------------------------------------------------------------------------------
void setup() {
//load steering values
STRAIGHT = EEPROM.read(0)*4;
FULL_LEFT = STRAIGHT - 30;
FULL_RIGHT = STRAIGHT + 40;
//engines' setup
pinMode(GO_A, OUTPUT);
pinMode(GO_B, OUTPUT);
......@@ -130,9 +143,12 @@ void setup() {
//display init
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.clearDisplay();
//calibrateSteering();
Serial.println("SETUP finished");
}
// -------------------------------------------------------------------------------------------
......@@ -150,7 +166,14 @@ void loop() {
signal = radio.readRSSI(); // read signal strength
}
setStalin();
//setStalin();
if (BUTTON & BUTTON != _BUTTON) {
delay(500);
BUTTON = false;
calibrateSteering();
_BUTTON = BUTTON;
}
// get temperature, check if it's ok
if (sensOk) {
......@@ -212,6 +235,25 @@ void setStalin() {
digitalWrite(STALIN, BUTTON);
}
void calibrateSteering() {
while(!BUTTON) {
if (radio.receiveDone()) {
processData();
if (radio.ACKRequested()) { //send ACK
radio.sendACK();
delay(10);
}
last_received = millis(); // signal check
signal = radio.readRSSI(); // read signal strength
}
setWheels();
}
STRAIGHT = STEER;
FULL_LEFT = STRAIGHT - 30;
FULL_RIGHT = STRAIGHT + 40;
EEPROM.write(0, STRAIGHT/4);
}
long getDistance() {
//send out a pulse
digitalWrite(TRIG, LOW);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment