Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ESP8266WiFi.h>
- IPAddress ip(1, 1, 1, 125);
- IPAddress gateway(1, 1, 1, 1);
- IPAddress subnet(255, 255, 255, 0);
- String ssid = "NAG";
- String heslo = "";
- int led1 = D5;
- int tlacitko = D8;
- int pinMotor[] = {16, 5, 4, 0};
- int delkaKroku = 500;
- int buttonState = 0; // current state of the button
- int lastButtonState = 0; // previous state of the button
- int startPressed = 0; // the time button was pressed
- int endPressed = 0; // the time button was released
- int timeHold = 0; // the time button is hold
- int timeReleased = 0; // the time button is released
- bool pripojOdpoj = false;
- int cas1;
- int cas2;
- int cas3;
- int poziceMot[8][4] = {
- {0,0,0,1},
- {0,0,1,1},
- {0,0,1,0},
- {0,1,1,0},
- {0,1,0,0},
- {1,1,0,0},
- {1,0,0,0},
- {1,0,0,1},
- };
- void otaceni(int smer) {
- while(smer > 0) {
- for(int i = 0; i < 8; i++) {
- for(int d = 0; d < 4; d++) {
- digitalWrite(pinMotor[d], poziceMot[i][d]);
- }
- delay(1);
- }
- smer--;
- }
- while(smer < 0){
- for(int i = 7; i >= 0; i--) {
- for(int d = 0; d < 4; d++) {
- digitalWrite(pinMotor[d], poziceMot[i][d]);
- }
- delay(1);
- }
- smer++;
- }
- }
- void pripojSeNaWIFI() {
- WiFi.config(ip, gateway, subnet);
- // Připojení k wifi síti
- WiFi.begin(ssid,heslo);
- Serial.print("Připojuji se k wifi síti");
- while (WiFi.status() != WL_CONNECTED)
- {
- delay(500);
- Serial.print(".");
- }
- Serial.println();
- Serial.print("Připojeno k WIFI, IP: : ");
- Serial.println(WiFi.localIP());
- }
- void kontrolaTlacitka() {
- buttonState = digitalRead(tlacitko);
- // button state changed
- if (buttonState != lastButtonState) {
- // the button was just pressed
- if (buttonState == HIGH) {
- startPressed = millis();
- timeReleased = startPressed - endPressed;
- if (timeReleased >= 1000) {
- Serial.print("Tlačítko stisknuto na více než 1 sekundu, ");
- pripojOdpoj = !pripojOdpoj;
- if(pripojOdpoj == true) {
- pripojSeNaWIFI();
- }
- else {
- Serial.println("Odpojuji od wifi sítě");
- WiFi.disconnect();
- }
- }
- // the button was just released
- } else {
- endPressed = millis();
- timeHold = endPressed - startPressed;
- }
- }
- // save the current state as the last state,
- //for next time through the loop
- lastButtonState = buttonState;
- }
- void setup() {
- // Inicializace Sériové linky
- Serial.begin(115200);
- Serial.println();
- WiFi.disconnect();
- for(int i = 0; i < 4; i++) {
- pinMode(pinMotor[i], OUTPUT);
- }
- pinMode(led1,OUTPUT);
- pinMode(tlacitko,INPUT_PULLUP);
- }
- void loop() {
- cas1 = millis();
- if(cas1-cas2 > delkaKroku) {
- otaceni(1);
- cas2 = millis();
- }
- if(WiFi.status() == WL_CONNECTED && cas1-cas3 > 500) {
- bool stavLed = !stavLed;
- digitalWrite(led1,stavLed);
- cas3 = millis();
- }
- kontrolaTlacitka();
- }
Advertisement
Add Comment
Please, Sign In to add comment