Главное меню

Юридическая помощь

Рекламодателям

Рекламодателям

Путь на сайте

оптика 2

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Fonts/FreeSerif9pt7b.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
char* myStrings[]={"This is string 1", "This is string 2", "This is string 3",
"This is string 4", "This is string 5","This is string 6"};
char str ;
int i=2;
int y=0;
const int movPin = 2;
void setup() {
  Serial.begin(115200);
//  pinMode(movPin, INPUT);
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println("SSD1306 allocation failed");
    for(;;);
    pinMode(movPin, INPUT);
  }

 

      Serial.begin(115200);
  //  if (y=0){
  //   String str = utf8rus("Андрей");
  //  }else
  //  delay(2000);
  // String str = utf8rus("Вася");
   
  // display.cp437(true);
  // display.clearDisplay();
  // display.setTextSize(2);            
  // display.setTextColor(WHITE);        
  // display.setCursor(30,20);            
  // display.println(str);
  // display.display();
 }
  void loop() {
  Serial.begin(9600);
   
  int r = analogRead(movPin);
    Serial.println(r);
   if (r>100){
  String str = utf8rus("Вася");
   display.cp437(true);
  display.clearDisplay();
  display.setTextSize(2);            
  display.setTextColor(WHITE);        
  display.setCursor(30,20);            
  display.println(str);
  display.display();
delay(100);
   }
  if (r<100) {String str = utf8rus("Андрей");
    display.cp437(true);
  display.clearDisplay();
  display.setTextSize(2);            
  display.setTextColor(WHITE);        
  display.setCursor(30,20);            
  display.println(str);
  display.display();
  }else
 delay(100);
display.clearDisplay();
//  String str = utf8rus("Вася");
//    display.cp437(true);
//   display.clearDisplay();
//   display.setTextSize(2);            
//   display.setTextColor(WHITE);        
//   display.setCursor(30,20);            
//   display.println(str);
//   display.display();
//   delay(2000);

 

  }
/* Функция перекодировки русских букв из UTF-8 в Win-1251 */
String utf8rus(String source)
{
  int i,k;
  String target;
  unsigned char n;
  char m[2] = { '0', '\0' };
  k = source.length(); i = 0;
  while (i < k) {
    n = source[i]; i++;
    if (n >= 0xC0) {
      switch (n) {
        case 0xD0: {
          n = source[i]; i++;
          if (n == 0x81) { n = 0xA8; break; }
          if (n >= 0x90 && n <= 0xBF) n = n + 0x30;
          break;
        }
        case 0xD1: {
          n = source[i]; i++;
          if (n == 0x91) { n = 0xB8; break; }
          if (n >= 0x80 && n <= 0x8F) n = n + 0x70;
          break;
        }
      }
    }
    m[0] = n; target = target + String(m);
  }
return target;
}