как выполнить задачу
- Войдите на сайт для отправки комментариев
Чт, 23/01/2020 - 05:39
/* Всем привет!!! Помогите доделать код!!! задача при зарядке устройства и подаче +5 вольт от USB нужно вывести на экран надпись "CHARGE" допустим на пин А0 с USB подается питание, а при питании от батареи не подается и работает в обычном режиме. Спасибо!!! * Arduino with SSD1306 OLED display (128x64 Pixel) and BME280 sensor. * BME280 is barometric pressure, temperature and humidity sensor. * This is a free software with NO WARRANTY. * https://simple-circuit.com/ */ #include <Wire.h> // include Arduino wire library (required for I2C devices) #include <Adafruit_GFX.h> // include Adafruit graphics library #include <Adafruit_SSD1306.h> // include Adafruit SSD1306 OLED display driver #include <Adafruit_BME280.h> // include Adafruit BME280 sensor library #define CHARG A0 #define OLED_RESET 4 // define display reset pin Adafruit_SSD1306 display(OLED_RESET); // initialize Adafruit display library // define device I2C address: 0x76 or 0x77 (0x77 is library default address) #define BME280_I2C_ADDRESS 0x76 //pinMode(10, OUTPUT); Adafruit_BME280 bme280; // initialize Adafruit BME280 library unsigned long timing; void setup(void) { pinMode(10, OUTPUT); pinMode(CHARG, INPUT); digitalWrite(10, HIGH); //включаем устройство // initialize the SSD1306 OLED display with I2C address = 0x3D display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // clear the display buffer. display.clearDisplay(); display.setTextSize(1); // text size = 1 display.setTextColor(WHITE, BLACK); // set text color to white and black background if(CHARG==HIGH ) display.setCursor(24, 10); display.print("CHARGE"); display.display(); display.setCursor(10, 0); // move cursor to position (0, 4) pixel display.print("HI MAXIM!!!"); //("W\nE\nA\nT\nH\nE\nR"); display.setCursor(24, 10); // move cursor to position (123, 4) pixel display.print("GOOD DAY!!!"); display.setCursor(123, display.getCursorY()); display.setCursor(38, 20); display.print("GOOD RACE!!!"); display.setCursor(123, display.getCursorY()); display.display(); delay(2000); display.clearDisplay();// update the display display.display(); // initialize the BME280 sensor if( bme280.begin(BME280_I2C_ADDRESS) == 0 ) { // connection error or device address wrong! while(1); // stay here } display.setCursor(10, 0); display.print("TEMP:"); display.setCursor(10, 10); display.print("HUMI:"); display.setCursor(10, 20); display.print("PRES:"); display.display(); // update the display } char _buffer[12]; void loop() { // read temperature, humidity and pressure from the BME280 sensor float temp = bme280.readTemperature(); // get temperature in degree Celsius float humi = bme280.readHumidity(); // get humidity in rH% float pres = bme280.readPressure(); // get pressure in Pa // print all data on the display // 1: print temperature if(temp < 0) sprintf(_buffer, "-%02u.%02u C", (int)abs(temp), (int)(abs(temp) * 100) % 100 ); else sprintf(_buffer, " %02u.%02u C", (int)temp, (int)(temp * 100) % 100 ); display.setCursor(55, 0); display.print(_buffer); // print degree symbols ( ° ) display.drawRect(105, 0, 3, 3, WHITE); // 2: print humidity sprintf(_buffer, "%02u.%02u %%", (int)humi, (int)(humi * 100) % 100 ); display.setCursor(50, 10); display.print(_buffer); // 3: print pressure sprintf(_buffer, "%04u.%02u hPa", (int)(pres/100), (int)((uint32_t)pres % 100) ); display.setCursor(50, 20); display.print(_buffer); // update the display display.display(); delay(1000); // wait a second if( millis()-timing > 10000) // задан интервал 100сек. { // timing = millis(10000); digitalWrite(10, LOW); //выключаем устройство timing = millis(); } } // end of code.
Спроси у автора кода. Пусть доделает
тут уже кто-то пытался доделать, правда с ошибками. С 42 по 46 строчку на экран выводится CHARGE
лучше бы по делу подсказали.
Тебе подсказали по делу в #2 - дельнее некуда.
так автор то я и есть и не могу доделать код
Все код допилен, тема закрыта!!!