Go Down

Topic: Wi-fi Kommunikation mit ESP 8266 und Arduino MKR Wifi 1010 (Read 70 times) previous topic - next topic

Mainsedora

Moin.
Code: [Select]

#include <ESC.h>
//#include <WiFiNINA.h>

//SSID of your network
//char ssid[] = "Mikromobilitaetesk8";
//password of your WPA Network
//char pass[] = "klaraesk8@";


#define SPEED_MIN (1000)                                          // Set the Minimum Speed in microseconds
#define SPEED_MAX (2000)                                          // Set the Minimum Speed in microseconds                                           
ESC myESC (2, SPEED_MIN, SPEED_MAX, 500);                         // ESC_Name (ESC PIN, Minimum Value, Maximum Value, Default Speed, Arm Value)
int deadmen= 0, oESC, cruiseButton = 1, pot = A0, val, curval = 1000;// Variable for the speed sent to the ESC
void setup() {
  Serial.begin(9600);
  pinMode(LED_BUILTIN, OUTPUT);                                   // LED Visual Output
  pinMode(pot, INPUT);
  pinMode(cruiseButton, INPUT);
  myESC.arm();                                                    // Send the Arm value so the ESC will be ready to take commands
  digitalWrite(LED_BUILTIN, HIGH);                                // LED High Once Armed
  delay (5000);                                                   // Wait for a while
  Serial.println("init finished");
}
void loop() {
   //WiFi.begin(ssid, pass);
  val = analogRead(pot);                                          //read potentiometer value
  Serial.println(val, DEC);
  val = map(val, 500, 1023, 1000, 2000);                          //map potentiomater value (0-1024 to 1000-2000 micro seconds);
  if (digitalRead(deadmen) == LOW){
    if (digitalRead(cruiseButton) == LOW) {                      //check if cruise button is pressed, if it is dont modify the curval
      // do nothing to curval
    }
    if (curval < val) {                                           //check if curval is less than potentiometers mapped value
      curval = curval + 8;                                        // if it is less, add 5 to the curval
    } else if (curval > val) {                                    //check if curval is more than potentiometers mapped value
      curval = curval - 10;                                        //if it is more, remove 5 from the curval
    }else if (curval > 1000) {                                     //if deadmans switch isnt turned and curval is more than 1000ms (throttle down value)
    curval = curval - 10;                                          //remove 5 from curval to start slowing down if above condition is true
  }
  }
  Serial.println(curval);
  myESC.speed(curval);                                            //write microseconds to esc
  delay(50);                                                      //delay the loop 50ms
}

Ich wollte mit diesem Code über Wifi mit dem ESP kommunizieren, um einen ESC anzusteuern. Nur weiß ich nicht wie ich das hinbekomme, weil ich recht neu in dieser Sparte bin. Zwar hab ich mich etwas in die Materie eingelesen, aber ich weiß nicht wie ich es umsetzen soll. Kann man mir da helfen?

Gruß
Mainsedora

Go Up