Skip to content

Commit

Permalink
rearranged file structure
Browse files Browse the repository at this point in the history
  • Loading branch information
sassybunsthebun committed May 20, 2024
1 parent 04c6f56 commit b281d81
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 deletions.
File renamed without changes.
12 changes: 8 additions & 4 deletions esp32/esp32.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -123,7 +123,7 @@ void loop()
}
client.loop();
}
/*

//A function that calculates the average value for the pressure and temperature sensors.
void readSensorAverage(){

Expand All @@ -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);
Expand Down Expand Up @@ -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!");
}

}
File renamed without changes.
File renamed without changes.
20 changes: 13 additions & 7 deletions zumobil/zumobil.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
#include <Zumo32U4Encoders.h>
#include <Zumo32U4.h>

/// 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;

Expand All @@ -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
Expand All @@ -35,7 +35,7 @@ void setup()

void loop()
{

delay(500);
//linjefolging();
}

Expand All @@ -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);
Expand All @@ -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.
}
Expand All @@ -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;
Expand Down

0 comments on commit b281d81

Please sign in to comment.