Components and supplies
webmos d1 mini
Graphic OLED, 128 x 64
3.7 volt battery
Project description
Code
coding.ino
arduino
1#include <ESP8266WiFi.h> 2#include <WiFiClient.h> 3#include <ESP8266WebServer.h> 4#include <SPI.h> 5#include <Wire.h> 6#include <Adafruit_GFX.h> 7#include <Adafruit_SSD1306.h> 8#define SCREEN_WIDTH 128 // OLED display width, in pixels 9#define SCREEN_HEIGHT 32 // OLED display height, in pixels 10#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin) 11#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32 12Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); 13#include <Servo.h> 14Servo myservo; 15//SSID and Password to your ESP Access Point 16const char* ssid = "tinny robot"; 17const char* password = ""; 18 19String command; //String to store app command state. 20ESP8266WebServer server(80); 21 22void setup() 23{ if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) 24 { 25 Serial.println(F("SSD1306 allocation failed")); 26 for(;;); // Don't proceed, loop forever 27 } 28 display.clearDisplay(); 29 display.setTextSize(2); // Draw 2X-scale text 30 display.setTextColor(SSD1306_WHITE); 31 display.setCursor(0, 0); 32 display.println(" Ready"); 33 display.display(); // Show initial text 34 delay(100); 35 myservo.attach(15); 36 myservo.write(0); 37 Serial.begin(115200); 38 39 40// Connecting WiFi 41 42 WiFi.mode(WIFI_AP); //Only Access point 43 WiFi.softAP(ssid, password); //Start HOTspot removing password will disable security 44 IPAddress myIP = WiFi.softAPIP(); 45 Serial.print("AP IP address: "); 46 Serial.println(myIP); 47 server.on ( "/", HTTP_handleRoot ); 48 server.onNotFound ( HTTP_handleRoot ); 49 server.begin(); 50} 51 52void loop() { 53 server.handleClient(); 54 55 command = server.arg("State"); 56 if (command == "F") goForword(); 57 else if (command == "S") stopRobot(); 58} 59 60void HTTP_handleRoot(void) { 61 62if( server.hasArg("State") ){ 63 Serial.println(server.arg("State")); 64 } 65 server.send ( 200, "text/html", "" ); 66 delay(1); 67} 68 69void goForword(){ 70 71 display.clearDisplay(); 72 display.setTextSize(2); // Draw 2X-scale text 73 display.setTextColor(SSD1306_WHITE); 74 display.setCursor(0, 0); 75 display.println(" Forward"); 76 display.display(); // Show initial text 77 delay(10); 78 display.clearDisplay(); 79 myservo.write(180); 80 delay(100); 81 myservo.write(0); 82 delay(100); 83 84 } 85 86void stopRobot(){ 87 myservo.write(0); 88 display.clearDisplay(); 89 display.setTextSize(2); // Draw 2X-scale text 90 display.setTextColor(SSD1306_WHITE); 91 display.setCursor(0, 0); 92 display.println(" Stop"); 93 display.display(); // Show initial text 94 delay(10); 95 display.clearDisplay(); 96 } 97
Comments
Only logged in users can leave comments
aakash11
6 Followers
•12 Projects
0
0