diff --git a/esp32/GPS.ino b/esp32/GPS/GPS.ino similarity index 100% rename from esp32/GPS.ino rename to esp32/GPS/GPS.ino diff --git a/esp32/esp32.ino b/esp32/esp32.ino index caf70ed..261bc26 100644 --- a/esp32/esp32.ino +++ b/esp32/esp32.ino @@ -64,7 +64,7 @@ Adafruit_GPS GPS(&GPSSerial); /// VARIABLES FOR DELAY WITH MILLIS /// unsigned long previousMillis = 0; -const int interval = 5000; +const int interval = 500; void setup() { @@ -123,7 +123,7 @@ void loop() } client.loop(); } -/* + //A function that calculates the average value for the pressure and temperature sensors. void readSensorAverage(){ @@ -143,7 +143,7 @@ void readSensorAverage(){ totalTemp = 0; //resets total value of temperature and pressure totalPressure = 0; } -*/ + void callback(char* topic, byte* message, unsigned int length) { Serial.print("Message arrived on topic: "); Serial.print(topic); @@ -176,7 +176,11 @@ void callback(char* topic, byte* message, unsigned int length) { if(millis() - previousMillis >= interval){ previousMillis = millis(); - wireTransmit(zumoaddress, kjoremodus); + //wireTransmit(zumoaddress, kjoremodus); + Wire.beginTransmission(zumoaddress); + Wire.write(kjoremodus); + Wire.endTransmission(); + Serial.print("message sent!"); } } diff --git a/zumobil/I2C_esp32_slave.ino b/zumobil/12C/I2C_esp32_slave.ino similarity index 100% rename from zumobil/I2C_esp32_slave.ino rename to zumobil/12C/I2C_esp32_slave.ino diff --git a/zumobil/I2C_zumo_master.ino b/zumobil/12C/I2C_zumo_master.ino similarity index 100% rename from zumobil/I2C_zumo_master.ino rename to zumobil/12C/I2C_zumo_master.ino diff --git a/zumobil/zumobil.ino b/zumobil/zumobil.ino index 4d80fa1..1bd02ee 100644 --- a/zumobil/zumobil.ino +++ b/zumobil/zumobil.ino @@ -2,13 +2,13 @@ #include #include -/// DEFINE THE INSTANCES OF THE CLASSES IN THE ZUMO32u4 LIBRARY /// +/// DEFINE THE INSTANCES OF THE CLASSES IN THE ZUMO32U4 LIBRARY /// Zumo32U4LineSensors lineSensors; Zumo32U4Motors motors; Zumo32U4OLED display; Zumo32U4Encoders encoder; -/// VARIABLER FOR LINE FOLLOWING /// +/// VARIABLES FOR LINE FOLLOWING /// int speed = 220; unsigned long previousMillis = 0; @@ -22,7 +22,7 @@ byte info = 0; void setup() { - Wire.begin(4); // join i2c bus with address #4 + Wire.begin(4);// join i2c bus with address #4 Wire.onReceive(receiveEvent); Serial.begin(9600); lineSensors.initFiveSensors(); //merges the line sensors @@ -35,7 +35,7 @@ void setup() void loop() { - + delay(500); //linjefolging(); } @@ -46,7 +46,7 @@ void receiveEvent(int howMany) //unsigned long currentMillis = millis(); //if(currentMillis - previousMillis >= 100){ //reads average sensor value every 5 seconds //previousMillis = currentMillis; - int kjoremodus = Wire.read(); + /*int kjoremodus = Wire.read(); Serial.println(kjoremodus); if(kjoremodus == 1){ motors.setSpeeds(50,150); @@ -60,8 +60,14 @@ void receiveEvent(int howMany) else if(kjoremodus == 4){ motors.setSpeeds(-100,-100); //} - delay(100); + */ + while(Wire.available()) { + char c = Wire.read(); // receive byte as a character + Serial.print(c); // print the character } + int x = Wire.read(); // receive byte as an integer + Serial.println(x); + // } //Inne i denne funksjonen kan man sette opp logikk for hvordan bilen skal bevege seg basert på verdien til kjoremodus. } @@ -78,7 +84,7 @@ void linjefolging(){ maxSpeed -= offset/2; unsigned int leftMotor = maxSpeed + offset - previousOffset/4; unsigned int rightMotor = maxSpeed - offset + previousOffset/4; - motors.setSpeeds( leftMotor, rightMotor); + motors.setSpeeds(leftMotor, rightMotor); } else if (sensorValue <= 1980) { offset = (2000 - sensorValue)/5;