Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "defines.h"
- #include <SPI.h>
- #include <WiFiNINA_Generic.h>
- #include <utility/wifi_drv.h>
- #include <WiFiUdp_Generic.h>
- #include <Wire.h>
- #include <Adafruit_GFX.h>
- #include <Adafruit_SSD1306.h>
- #include <BMx280I2C.h>
- #include <MPU9250_WE.h>
- //Scheduler
- #include <Scheduler.h>
- #if defined(ARDUINO_ARCH_SAMD) && (USB_PID == 0x8D21)
- #define Serial SerialUSB
- #endif
- //
- //I2C device found at address 0x3C ! DISPLAY
- //I2C device found at address 0x60 !
- //I2C device found at address 0x68 ! ACCELEROMETER
- //I2C device found at address 0x6B !
- //I2C device found at address 0x76 ! BAROMETER/TEMP SENSOR
- //SENSORS/DISPLAY
- #define MPU9250_ADDR 0x68 // Accelerometer Address
- #define SCREEN_ADDRESS 0x3C // Display
- #define BMP280_ADDR 0x76 // Barometer
- #define SCREEN_WIDTH 128 // OLED display width, in pixels
- #define SCREEN_HEIGHT 64 // OLED display height, in pixels
- #define OLED_RESET -1 // Sharing reset pin
- //VIDOR 4000 RGB LED
- #define RGBLEDR 25
- #define RGBLEDG 26
- #define RGBLEDB 27
- //Stupid things that aren't really requiered
- #define NUMFLAKES 10 // Number of snowflakes in the animation example
- #define LOGO_HEIGHT 16
- #define LOGO_WIDTH 16
- Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
- MPU9250_WE myMPU9250 = MPU9250_WE(MPU9250_ADDR);
- BMx280I2C bmx280(BMP280_ADDR);
- //static const unsigned char PROGMEM logo_bmp[] =
- //{ 0b00000000, 0b11000000,
- // 0b00000001, 0b11000000,
- // 0b00000001, 0b11000000,
- // 0b00000011, 0b11100000,
- // 0b11110011, 0b11100000,
- // 0b11111110, 0b11111000,
- // 0b01111110, 0b11111111,
- // 0b00110011, 0b10011111,
- // 0b00011111, 0b11111100,
- // 0b00001101, 0b01110000,
- // 0b00011011, 0b10100000,
- // 0b00111111, 0b11100000,
- // 0b00111111, 0b11110000,
- // 0b01111100, 0b11110000,
- // 0b01110000, 0b01110000,
- // 0b00000000, 0b00110000
- //};
- /////////////////////////////////////////////////////////////////////////////////////////////
- // Global variables to keep track of update rates
- unsigned long startTime, lastPrint, accelReadCounter, gyroReadCounter, magReadCounter, tempReadCounter;
- const unsigned int PRINT_RATE = 100;
- unsigned int localPort = 9000; // local port to listen on
- unsigned int localStatePort = 8890; // local state port
- unsigned int localVideoPort = 11111; // local video port
- //MY TELLOS: 627706-FDFD3B
- char packetBuffer[255], inputBuffer[90 + 1], msgData[90], telloIP[] = "192.168.10.1", apIP[] = "0.0.0.0", ssid[] = "TELLO-627706", pass[] = "";
- uint16_t telloPort = 8889, telloStatePort = 8890, telloVideo = 11111;
- const int ledPin = LED_BUILTIN; //red led vidor 4000 - weirdly... it's backwards (high is low and low is high)
- bool telloReady = false;
- String a, b, c, d, t;
- int x, y, z, keyIndex;
- double xyz[3];
- static unsigned long lastTimeItHappened = 0;
- String LF;
- WiFiUDP Udp;
- WiFiClient client1;
- WiFiServer serverHTML(80);
- WiFiServer serverSTATUS(8890);
- WiFiServer serverVIDEO(11111);
- int status1 = WL_IDLE_STATUS;
- int status2 = WL_IDLE_STATUS;
- //////////////////////////////////////////////////////////////////////////////////////////////
- void initBoard() {
- //Configure rgb builtin
- WiFiDrv::pinMode(RGBLEDR, OUTPUT);
- WiFiDrv::pinMode(RGBLEDG, OUTPUT);
- WiFiDrv::pinMode(RGBLEDB, OUTPUT);
- //Initialize serial and wait for port to open:
- Serial.begin(115200);
- startTime = millis();
- inputBuffer[0] = '\0'; //Initialize string buffer to terminator.
- Serial.print(BOARD_NAME);
- Serial.print(", ");
- Serial.println(WIFININA_GENERIC_VERSION);
- // check for the WiFi module:
- if (WiFi.status() == WL_NO_MODULE)
- {
- Serial.println(F("Communication with WiFi module failed!"));
- // don't continue
- while (true);
- }
- String fv = WiFi.firmwareVersion();
- if (fv < WIFI_FIRMWARE_LATEST_VERSION)
- {
- Serial.print(F("NINA FW v"));
- Serial.print(fv);
- Serial.print(F(" -> Newer NINA FW v"));
- Serial.print(WIFI_FIRMWARE_LATEST_VERSION);
- Serial.println("\n");
- }
- Wire.begin();
- if (!myMPU9250.init()) {
- Serial.println("MPU9250 does not respond");
- }
- else {
- Serial.println("MPU9250 is connected");
- }
- myMPU9250.setMagOpMode(AK8963_CONT_MODE_8HZ);
- myMPU9250.setAccRange(MPU9250_ACC_RANGE_16G);
- myMPU9250.enableAccDLPF(true);
- myMPU9250.setAccDLPF(MPU9250_DLPF_0);
- //Magnometer Ready?
- myMPU9250.isMagDataReady();
- //
- //begin() checks the Interface, reads the sensor ID (to differentiate between BMP280 and BME280)
- //and reads compensation parameters.
- Serial.println("Starting Barometer");
- if (!bmx280.begin())
- {
- Serial.println("begin() failed. check your BMx280 Interface and I2C Address.");
- while (1);
- }
- Serial.println("Barometer Working!");
- if (bmx280.isBME280())
- Serial.println("sensor is a BME280");
- else
- Serial.println("sensor is a BMP280");
- //reset sensor to default parameters.
- bmx280.resetToDefaults();
- //by default sensing is disabled and must be enabled by setting a non-zero
- //oversampling setting.
- //set an oversampling setting for pressure and temperature measurements.
- bmx280.writeOversamplingPressure(BMx280MI::OSRS_P_x16);
- bmx280.writeOversamplingTemperature(BMx280MI::OSRS_T_x16);
- //if sensor is a BME280, set an oversampling setting for humidity measurements.
- if (bmx280.isBME280()) {
- bmx280.writeOversamplingHumidity(BMx280MI::OSRS_H_x16);
- }
- //
- //BAROMETER
- Scheduler.start(THREAD3START, THREAD3LOOP);
- //SCREEN
- if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
- Serial.println(F("SSD1306 allocation failed"));
- for (;;); // Don't proceed, loop forever
- }
- Serial.println("Screen Enabled");
- Serial.println("Position the MPU9250 flat and don't move it - calibrating...");
- //DOF CALIBRATION
- for (int i = 0; i < 15; i++)
- {
- //10DOF
- xyzFloat gValue = myMPU9250.getGValues();
- xyzFloat angle = myMPU9250.getAngles();
- xyzFloat magValue = myMPU9250.getMagValues(); // returns magnetic flux density [µT]
- //SCREEN
- display.clearDisplay(); // Clear display buffer
- display.println(F("CALIBRATE"));
- //display.fillRect(126/2 + (-angle.y), 64/2+(-angle.x), 2, 2, SSD1306_INVERSE);
- display.drawLine(0, 32 + (-map(gValue.x, -1.0f, 1.0f, -32, 32)), 64, 32 + (-map(gValue.x, -1.0f, 1.0f, -32, 32)), SSD1306_WHITE);
- display.drawLine(32 + (-map(gValue.y, -1.0f, 1.0f, -32, 32)), 0, 32 + (-map(gValue.y, -1.0f, 1.0f, -32, 32)), 64, SSD1306_WHITE);
- //display.drawRect(0, 0, 64, 64, SSD1306_INVERSE);
- display.setTextSize(1);
- display.setTextColor(SSD1306_WHITE);
- display.setCursor(70, 0);
- display.println(F("CALIBRATE"));
- display.setCursor(70, 32);
- display.println(F("ANGLE"));
- display.setCursor(70, 40);
- display.println(String(angle.x));
- display.setCursor(70, 48);
- display.println(String(angle.y));
- display.setCursor(70, 56);
- display.println(String(angle.z));
- display.setCursor(70, 64);
- display.display(); // Update screen with each newly-drawn line
- delay(5);
- myMPU9250.autoOffsets();
- }
- Serial.println("Done!");
- }
- /////////////////////////////////////////////////////////////////////////////////////////
- //Set the Vidor 4000 RGB led color
- void setRGB(int r, int g, int b)
- {
- WiFiDrv::analogWrite(RGBLEDR, r); // RED
- WiFiDrv::analogWrite(RGBLEDG, g); // GREEN
- WiFiDrv::analogWrite(RGBLEDB, b); // BLUE
- }
- // Sends data to the tello UDP server ip
- void sendData(char* SIP, uint16_t SPort, String t = "battery?") {
- char a[60 + 1];
- t.toCharArray(a, 60 + 1);
- Udp.beginPacket(SIP, SPort);
- Udp.write(a);
- Udp.endPacket();
- }
- ////////////////////////////////////////////////////////////////////////////////////////////
- //Creates an access point on the vidor 4000 for the tello to connect to.
- void createAP() {
- IPAddress ip(192, 168, 10, 1);
- IPAddress gateway(0, 0, 0, 0);
- IPAddress subnet(255, 255, 255, 0);
- IPAddress dns(0, 0, 0, 0);
- WiFi.config(ip, dns, gateway, subnet);
- WiFi.config(IPAddress(192, 168, 10, 1));
- WiFi.setHostname("2022-GSAVAGE-CONCEPT-CONTROLLER-V1");
- Serial.println("Creating Access Point");
- status2 = WiFi.beginAP("TELLO-MASTER", "3ow58cnoerlsijdn");
- if (status2 != WL_AP_LISTENING) {
- Serial.println("Creating access point failed");
- // don't continue
- while (true);
- }
- delay(10000);
- printAPStatus();
- Serial.println("AP SSID: TELLO-MASTER, Pass: 3ow58cnoerlsijdn");
- serverVIDEO.begin();
- delay(2000);
- Serial.println("TELLO VIDEO Server Listening (11111)");
- serverSTATUS.begin();
- delay(2000);
- Serial.println("TELLO STATUS Server Listening (8890)");
- serverHTML.begin();
- delay(2000);
- Serial.println("TELLO WEB Server Listening (80)");
- Serial.println("Starting State UDP Server Port 8890");
- Udp.begin(localStatePort);
- delay(2000);
- Serial.println("Starting Video UDP Server Port 11111");
- Udp.begin(localVideoPort);
- delay(2000);
- telloReady = true;
- Serial.println("TELLO SHOULD BE READY NOW");
- //Init Web Server Thread
- Scheduler.start(THREAD2START, THREAD2LOOP);
- }
- //////////////////////////////////////////////////////////////////////////////////////////
- void connectWifi() {
- //nUpdating display
- display.clearDisplay(); // Clear display buffer
- display.drawCircle(display.width() - 10, display.height() / 2, 6, SSD1306_WHITE);
- display.setTextSize(2);
- display.setTextColor(SSD1306_WHITE);
- display.setCursor(0, 0);
- display.println(F("TELLO SCAN"));
- display.setTextSize(1);
- display.setCursor(0, 22);
- display.println(F("LOOKING FOR TELLO"));
- display.println((String)telloIP);
- display.setCursor(0, 38);
- display.print(F("PORT:"));
- display.println((String)telloPort);
- display.display(); // Update screen
- // Attempt to connect to Wifi network:
- IPAddress ip(192, 168, 10, 1);
- IPAddress gateway(0, 0, 0, 0);
- IPAddress subnet(255, 255, 255, 0);
- IPAddress dns(0, 0, 0, 0);
- WiFi.config(ip, dns, gateway, subnet);
- WiFi.setHostname("2022-CONCEPT-CONTROLLER-V1");
- while (status1 != WL_CONNECTED)
- {
- Serial.print(F("Trying to connect to SSID: "));
- Serial.println(ssid);
- status1 = WiFi.begin(ssid, pass);
- delay(1000);
- }
- Serial.println("Connected!");
- //Print connection info
- printWiFiStatus();
- // Start udp port 9000
- Serial.println(F("Opening listen port"));
- Udp.begin(localPort);
- delay(10000);
- Serial.println(F("Sending SDK command"));
- //Send command to tello
- sendData(telloIP, telloPort, "command"); //Enable control over tello
- delay(1000);
- sendData(telloIP, telloPort, "takeoff"); //Enable control over tello
- //todo
- //sendData(telloIP, telloPort, "land"); //Enable control over tello
- //Serial.println(F("Sending StreamOn command"));
- //sendData(telloIP, telloPort, "streamon");//Enable Video Stream
- //Serial.println(F("Sending AP command: ap TELLO-MASTER 3ow58cnoerlsijdn"));
- //sendData(telloIP, telloPort, "ap TELLO-MASTER 3ow58cnoerlsijdn"); //Only works with EDU version
- //command tello via serial
- Scheduler.start(THREAD0START, THREAD0LOOP);
- //Parse UDP Packets
- Scheduler.start(THREAD1START, THREAD1LOOP);
- }
- ///////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- void setup()
- {
- //Start Devices
- initBoard();
- //Display Circle Loop
- Scheduler.start(THREAD4START, THREAD4LOOP);
- //Access Point
- //createAP();
- //Tello WiFi
- connectWifi();
- telloReady = true;
- }
- //////////////////////////////////////////////////////////////////////////////////////////
- String CONTROL;
- void loop()
- {
- //10DOF
- xyzFloat gValue = myMPU9250.getGValues();
- xyzFloat angle = myMPU9250.getAngles();
- xyzFloat magValue = myMPU9250.getMagValues(); // returns magnetic flux density [µT]
- //SCREEN
- display.clearDisplay(); // Clear display buffer
- display.drawCircle(display.width() / 4, display.height() / 2, 31, SSD1306_WHITE);
- display.drawCircle(display.width() / 4, display.height() / 2, 2, SSD1306_WHITE);
- //display.fillRect(126/2 + (-angle.y), 64/2+(-angle.x), 2, 2, SSD1306_INVERSE);
- display.drawLine(0, 32 + (-map(gValue.x, -1.0f, 1.0f, -32, 32)), 64, 32 + (-map(gValue.x, -1.0f, 1.0f, -32, 32)), SSD1306_WHITE);
- display.drawLine(32 + (-map(gValue.y, -1.0f, 1.0f, -32, 32)), 0, 32 + (-map(gValue.y, -1.0f, 1.0f, -32, 32)), 64, SSD1306_WHITE);
- //display.drawRect(0, 0, 64, 64, SSD1306_INVERSE);
- display.setTextSize(0.1f);
- display.setTextColor(SSD1306_WHITE);
- display.setCursor(70, 0);
- display.println(F("XYZ"));
- display.setCursor(70, 8);
- display.println(String(map(gValue.x, -1.0f, 1.0f, -100, 100)));
- display.setCursor(70, 16);
- display.println(String(map(gValue.y, -1.0f, 1.0f, -100, 100)));
- display.setCursor(70, 24);
- display.println(String(map(gValue.z, -1.0f, 1.0f, -100, 100)));
- display.setCursor(70, 32);
- display.println(F("ANGLE"));
- display.setCursor(70, 40);
- display.println(String(angle.x));
- display.setCursor(70, 48);
- display.println(String(angle.y));
- display.setCursor(70, 56);
- display.println(String(angle.z));
- display.setCursor(70, 64);
- display.display(); // Update screen with each newly-drawn line
- //UDP to send command string to control the axis X,Y OF THE DRONE
- CONTROL = "rc " + (String)map(gValue.x, -1.0f, 1.0f, -100, 100) + " " + (String)map(gValue.y, -1.0f, 1.0f, -100, 100) + " 0 0";
- //String sxyz = String(angle.x) + " " + String(angle.y) + " " + String(angle.z);
- //Serial.println(CONTROL);
- //Serial.println(sxyz);
- sendData(telloIP, telloPort, CONTROL);
- //////////////////////////////////////////////////////////////////////////
- //Check battery every 14 seconds (Keeps connection alive)
- // if (millis() - lastTimeItHappened >= 14000) { // 14 seconds later
- // lastTimeItHappened = millis();
- // //Serial.println(F("Repeating (14s) Battery?"));
- // sendData(telloIP, telloPort, "battery?");
- // }
- }
- void THREAD0START(){}
- void THREAD0LOOP()
- {
- //command tello via serial
- if (Serial.available() > 0)
- {
- char input = Serial.read();
- static int s_len;
- if (s_len >= 90) {
- } else if (input != '\n' && input != '\r') {
- inputBuffer[s_len++] = input;
- } else {
- if (telloReady) {
- sendData(telloIP, telloPort, inputBuffer);
- Serial.print("Serial2UDP -> ");
- Serial.println(inputBuffer);
- memset(inputBuffer, 0, sizeof(inputBuffer));
- s_len = 0;
- }
- }
- }
- }
- void THREAD1START(){}
- void THREAD1LOOP()
- {
- // if there's data available on UDP for us
- int packetSize = Udp.parsePacket();
- if (packetSize)
- {
- Serial.print(F("UDP Received <- size "));
- Serial.print(packetSize);
- Serial.print(F(" - FROM IP: "));
- IPAddress remoteIp = Udp.remoteIP();
- Serial.print(remoteIp);
- Serial.print(F(", Port: "));
- Serial.print(Udp.remotePort());
- int len = Udp.read(packetBuffer, 255);
- if (len > 0)
- {
- packetBuffer[len] = 0;
- }
- Serial.print(F(" MSG: "));
- Serial.println(packetBuffer);
- }
- }
- void THREAD2START(){}
- void THREAD2LOOP()
- {
- //////////////////////////////////////////////////////////////////////
- //Something comnnects to the AP
- // if (status1 != WiFi.status()) {
- // // it has changed update the variable
- // status1 = WiFi.status();
- // if (status1 == WL_CONNECTED) {
- // // a device has connected to the AP
- // Serial.println("Device connected to AP");
- // sendData(telloIP, telloPort, "command");
- // delay(1000);
- // sendData(telloIP, telloPort, "streamon");
- // delay(5000);
- // sendData(telloIP, telloPort, "takeoff");
- // delay(5000);
- // sendData(telloIP, telloPort, "land");
- // } else {
- //
- // // a device has disconnected from the AP, and we are back in listening mode
- // Serial.print("Device disconnected from AP: ");
- // }
- // }
- /////////////////////////////////////////////////////////////////////////
- //
- // client1 = serverHTML.available(); // listen for incoming clients
- // if (client1) { // if you get a client,
- // Serial.println("AP client connected"); // print a message out the serial port
- // String currentLine = ""; // make a String to hold incoming data from the client
- // while (client1.connected()) { // loop while the client's connected
- // if (client1.available()) { // if there's bytes to read from the client,
- // char c = client1.read(); // read a byte, then
- // Serial.write(c); // print it out the serial monitor
- // if (c == '\n') { // if the byte is a newline character
- // if (currentLine.length() == 0) {
- // client1.println("HTTP/1.1 200 OK");
- // client1.println("Content-type:text/html");
- // client1.println();
- // client1.print("<html><head></head><body>");
- // client1.print(client1);
- // //client1.print("<video src=\"");
- // //client1.print("udp://192.168.10.1:11111\"""brightsign-properties=\"""StreamTimeout:0;StreamLowLatency:0;\"");
- // //client1.print(">");
- // client1.print("Click <a href=\"/E\">HERE</a> to take control<br>Click <a href=\"/H\">HERE</a> to take off<br>Click <a href=\"/L\">HERE</a> to land<br>");
- // client1.print("</body></html>");
- // client1.println();
- // break;
- // }
- // else { // if you got a newline, then clear currentLine:
- // currentLine = "";
- // }
- // }
- // else if (c != '\r') { // anything but carriage return
- // currentLine += c; // add it to the end of the currentLine
- // }
- // // Check to see if the client request was "GET /H" or "GET /L":
- // if (currentLine.endsWith("GET /E")) {
- // sendData(telloIP, telloPort, "command");
- // sendData("192.168.4.1", telloPort, "command");
- // sendData("0.0.0.0", telloPort, "command");
- // sendData(telloIP, telloStatePort, "command");
- // sendData("192.168.4.1", telloStatePort, "command");
- // sendData("0.0.0.0", telloStatePort, "command");
- // }
- // if (currentLine.endsWith("GET /H")) {
- // sendData(telloIP, telloPort, "takeoff");
- // sendData("192.168.4.1", telloPort, "takeoff");
- // sendData("0.0.0.0", telloPort, "takeoff");
- // sendData(telloIP, telloStatePort, "takeoff");
- // sendData("192.168.4.1", telloStatePort, "takeoff");
- // sendData("0.0.0.0", telloStatePort, "takeoff");
- // }
- // if (currentLine.endsWith("GET /L")) {
- // sendData(telloIP, telloPort, "land");
- // sendData("192.168.4.1", telloPort, "land");
- // sendData("0.0.0.0", telloPort, "land");
- // sendData(telloIP, telloStatePort, "land");
- // sendData("192.168.4.1", telloStatePort, "land");
- // sendData("0.0.0.0", telloStatePort, "land");
- // }
- // }
- // }
- // client1.stop();
- // }
- }
- void THREAD3START() {}
- void THREAD3LOOP() {
- //BAROMETER
- if (!bmx280.measure())
- {
- Serial.println("could not start measurement, is a measurement already running?");
- return;
- }
- do
- {
- delay(100);
- } while (!bmx280.hasValue());
- Serial.print("Pressure: ");
- Serial.print(bmx280.getPressure());
- Serial.print(" - Pressure (64 bit): ");
- Serial.print(bmx280.getPressure64());
- Serial.print(" - Temperature: ");
- Serial.println(bmx280.getTemperature());
- //important: measurement data is read from the sensor in function hasValue() only.
- //make sure to call get*() functions only after hasValue() has returned true.
- if (bmx280.isBME280())
- {
- Serial.print("Humidity: ");
- Serial.println(bmx280.getHumidity());
- }
- }
- void THREAD4START() {
- }
- int invert = SSD1306_WHITE;
- int scalec = 0;
- void THREAD4LOOP() {
- for (scalec = 0; scalec < 10; scalec++)
- {
- display.drawCircle(display.width() - 10, display.height() / 2, scalec, invert);
- delay(10);
- display.display();
- }
- invert = !invert;
- }
- ///////////////////////////////////////////////////////////////////////////////////////////
- void curve(int x1, int y1, int z1, int x2, int y2, int z2, int spd)
- {
- String m = "curve " + String(x1) + " " + String(y1) + " " + String(z1) + " " + String(x2) + " " + String(y2) + " " + String(z2) + " " + String(spd);
- sendData(telloIP, telloPort, m);
- }
- ///////////////////////////////////////////////////////////////////////////////////////////
- void printWiFiStatus()
- {
- // print your board's IP address:
- IPAddress ip = WiFi.localIP();
- Serial.print(F("IP Address: "));
- Serial.print(ip);
- // print the received signal strength:
- long rssi = WiFi.RSSI();
- Serial.print(F(" Signal strength (RSSI):"));
- Serial.print(rssi);
- Serial.println(F(" dBm"));
- }
- //////////////////////////////////////////////////////////////////////////////////////////////
- void printAPStatus()
- {
- IPAddress ip;
- Serial.print("SSID: ");
- Serial.println(WiFi.SSID());
- ip = WiFi.localIP();
- Serial.print("IP Address : ");
- Serial.println(ip);
- ip = WiFi.gatewayIP();
- Serial.print("IP Gateway : ");
- Serial.println(ip);
- ip = WiFi.subnetMask();
- Serial.print("Subnet Mask : ");
- Serial.println(ip);
- ip = WiFi.localIP();
- Serial.print("To see this page in action, open a browser to http://");
- Serial.println(ip);
- }
- /////////////////////////////////////////////////////////////////////////////////////////
- void printMacAddress(byte mac[]) {
- for (int i = 5; i >= 0; i--) {
- if (mac[i] < 16) {
- Serial.print("0");
- }
- Serial.print(mac[i], HEX);
- if (i > 0) {
- Serial.print(":");
- }
- }
- Serial.println();
- }
- ////////////////////////////////////////////////////////////////////////////////////////
- float map(float x, float in_min, float in_max, float out_min, float out_max)
- {
- return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
- }
- ////////////////////////////////////////////////////////////////////////////////////////
- void drawrect(void) {
- display.clearDisplay();
- for (int16_t i = 0; i < display.height() / 2; i += 2) {
- display.drawRect(i, i, display.width() - 2 * i, display.height() - 2 * i, SSD1306_WHITE);
- display.display(); // Update screen with each newly-drawn rectangle
- delay(1);
- }
- delay(2000);
- }
- void drawcircle(void) {
- display.clearDisplay();
- for (int16_t i = 0; i < max(display.width(), display.height()) / 2; i += 2) {
- display.drawCircle(display.width() / 2, display.height() / 2, i, SSD1306_WHITE);
- display.display();
- delay(1);
- }
- delay(2000);
- }
- void drawroundrect(void) {
- display.clearDisplay();
- for (int16_t i = 0; i < display.height() / 2 - 2; i += 2) {
- display.drawRoundRect(i, i, display.width() - 2 * i, display.height() - 2 * i,
- display.height() / 4, SSD1306_WHITE);
- display.display();
- delay(1);
- }
- delay(2000);
- }
- void drawtriangle(void) {
- display.drawTriangle(
- display.width() / 2 , display.height() / 2 - i,
- display.width() / 2 - i, display.height() / 2 + i,
- display.width() / 2 + i, display.height() / 2 + i, SSD1306_WHITE);
- display.display();
- delay(1);
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////
- //void testdrawbitmap(void) {
- // display.clearDisplay();
- //
- // display.drawBitmap(
- // (display.width() - LOGO_WIDTH ) / 2,
- // (display.height() - LOGO_HEIGHT) / 2,
- // logo_bmp, LOGO_WIDTH, LOGO_HEIGHT, 1);
- // display.display();
- // delay(1000);
- //}
- //////////////////////////////////////////////////////////////////////////////////////////////////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement