Caramel Iot for Arduino ソースコード

概要については、こちらのページをご覧ください。

V 0.1


// IMPORTANT: ELEGOO_TFTLCD LIBRARY MUST BE SPECIFICALLY
// CONFIGURED FOR EITHER THE TFT SHIELD OR THE BREAKOUT BOARD.
// SEE RELEVANT COMMENTS IN Elegoo_TFTLCD.h FOR SETUP.
//Technical support:goodtft@163.com

#include <Elegoo_GFX.h>    // Core graphics library
#include <Elegoo_TFTLCD.h> // Hardware-specific library
#include <TouchScreen.h>

#if defined(__SAM3X8E__)
#undef __FlashStringHelper::F(string_literal)
#define F(string_literal) string_literal
#endif


#define YP A3  // must be an analog pin, use "An" notation!
#define XM A2  // must be an analog pin, use "An" notation!
#define YM 9   // can be a digital pin
#define XP 8   // can be a digital pin

// The control pins for the LCD can be assigned to any digital or
// analog pins...but we'll use the analog pins as this allows us to
// double up the pins with the touch screen (see the TFT paint example).
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0

#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin

// When using the BREAKOUT BOARD only, use these 8 data lines to the LCD:
// For the Arduino Uno, Duemilanove, Diecimila, etc.:
//   D0 connects to digital pin 8  (Notice these are
//   D1 connects to digital pin 9   NOT in order!)
//   D2 connects to digital pin 2
//   D3 connects to digital pin 3
//   D4 connects to digital pin 4
//   D5 connects to digital pin 5
//   D6 connects to digital pin 6
//   D7 connects to digital pin 7
// For the Arduino Mega, use digital pins 22 through 29
// (on the 2-row header at the end of the board).

// Assign human-readable names to some common 16-bit color values:
#define	BLACK   0x0000
#define	BLUE    0x001F
#define	RED     0xF800
#define	GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW1 0xFFF0
#define YELLOW  0xFFC0
#define YELLOW2 0xFF80
#define WHITE   0xFFFF

Elegoo_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
// If using the shield, all control and data lines are fixed, and
// a simpler declaration can optionally be used:
// Elegoo_TFTLCD tft;


//Touch For New ILI9341 TP
#define TS_MINX 120
#define TS_MAXX 900

#define TS_MINY 70
#define TS_MAXY 920


void setup(void) {
  pinMode(13, OUTPUT);
  Serial.begin(9600);
  Serial.println(F("TFT LCD test"));

#ifdef USE_Elegoo_SHIELD_PINOUT
  Serial.println(F("Using Elegoo 2.8\" TFT Arduino Shield Pinout"));
#else
  Serial.println(F("Using Elegoo 2.8\" TFT Breakout Board Pinout"));
#endif

  Serial.print("TFT size is "); Serial.print(tft.width()); Serial.print("x"); Serial.println(tft.height());

  tft.reset();
  tft.setTextColor(WHITE);
  tft.setTextSize(6);
  tft.println("booting...");

  uint16_t identifier = tft.readID();
  if (identifier == 0x9325) {
    Serial.println(F("Found ILI9325 LCD driver"));
  } else if (identifier == 0x9328) {
    Serial.println(F("Found ILI9328 LCD driver"));
  } else if (identifier == 0x4535) {
    Serial.println(F("Found LGDP4535 LCD driver"));
  } else if (identifier == 0x7575) {
    Serial.println(F("Found HX8347G LCD driver"));
  } else if (identifier == 0x9341) {
    Serial.println(F("Found ILI9341 LCD driver"));
  } else if (identifier == 0x8357) {
    Serial.println(F("Found HX8357D LCD driver"));
  } else if (identifier == 0x0101)
  {
    identifier = 0x9341;
    Serial.println(F("Found 0x9341 LCD driver"));
  } else {
    Serial.print(F("Unknown LCD driver chip: "));
    Serial.println(identifier, HEX);
    Serial.println(F("If using the Elegoo 2.8\" TFT Arduino shield, the line:"));
    Serial.println(F("  #define USE_Elegoo_SHIELD_PINOUT"));
    Serial.println(F("should appear in the library header (Elegoo_TFT.h)."));
    Serial.println(F("If using the breakout board, it should NOT be #defined!"));
    Serial.println(F("Also if using the breakout, double-check that all wiring"));
    Serial.println(F("matches the tutorial."));
    identifier = 0x9341;

  }

  tft.begin(identifier);

  Serial.println(F("Benchmark                Time (microseconds)"));

  Serial.print(F("Screen fill              "));
  Serial.println(testFillScreen());
  delay(50);

  Serial.print(F("Topmenu                  "));
  //Serial.println(testText());
  tft.fillScreen(BLACK);

  Serial.println(F("Done!"));
}


static int reboot = 0;
static String str;

void loop(void) {
LOOPSTART:
  while (1) {
    tft.fillScreen(BLACK);
    testLines(random(0xffff));
    testText();


    //delay(6000);

    //13ピンのSDをオンにする意味は不明。記述がないスケッチ例もある
    digitalWrite(13, HIGH);

    //タッチスクリーンライブラリのgetPoint関数を利用してTSPoint(位置情報)の
    //変数pに現在の位置を代入。単位はADC値と同じ
    //古いライブラリではTSPointがPointとなっていることあり
    TSPoint p = ts.getPoint();
    pinMode(YP, OUTPUT);     //.kbv these pins are shared with TFT
    pinMode(XM, OUTPUT);     //.kbv these pins are shared with TFT

    //同じく不明
    digitalWrite(13, LOW);
  }
}

unsigned long testFillScreen() {
  unsigned long start = micros();
  tft.fillScreen(BLACK);
  tft.fillScreen(YELLOW1);
  tft.fillScreen(YELLOW);
  tft.fillScreen(YELLOW2);
  tft.fillScreen(BLACK);
  return micros() - start;
}

unsigned long testText() {


  //tft.fillScreen(BLACK);
  int timer;
  tft.setRotation(3);
  unsigned long start = micros();
  tft.setCursor(0, 0);
  tft.setTextColor(WHITE);  tft.setTextSize(1);
  tft.println("Welcome!");
  tft.setTextColor(YELLOW); tft.setTextSize(2);
  tft.println("2020 03/14 14:57");
  tft.setTextSize(1);
  tft.print("This computer is boot on ");
  tft.setTextColor(RED);
  timer = micros() / 1000000;
  tft.print(timer);
  tft.setTextColor(YELLOW);
  tft.println(" seconds ago.");
  tft.setTextColor(RED);
  tft.println("https://caramelos.xyz/other/arduino");
  tft.println();
  tft.setTextColor(GREEN);
  tft.setTextSize(3);
  tft.println("Hi,everyone!");
  tft.setTextColor(YELLOW1); tft.setTextSize(2);
  tft.println("Welcome to\n Caramel iot.");
  tft.setTextColor(GREEN);   tft.setTextSize(1);
  tft.println("This system was maked by TOKIENOKI.");
  tft.println("I can anything!");
  tft.println("I want to do your help always.");
  tft.println("When you call to help me,");
  tft.println("I can support you!");
  tft.println("Contact : https://caramelos.xyz/twitter");
  tft.setTextSize(2);
  tft.println("Hope your happiness!");
  tft.setTextColor(RED);     tft.setTextSize(1);
  tft.println("Please touch me!");
  tft.setCursor(0, 0);
  tft.setRotation(0);
  tft.setTextSize(3);
  tft.setTextColor(YELLOW);
  tft.println("Powered by");
  tft.setTextSize(2);
  tft.println("Caramel OS Dev team.");



  tft.setRotation(3);
  tft.setCursor(0, 190);
  tft.setTextSize(1);
  tft.setTextColor(WHITE);
  tft.println("Notification:");
  tft.setTextSize(2);

  if (str[0] != '\0') {
    Serial.print("表示された通知:");
    Serial.println(str);
    for (int j = 50; j > 21; j--) {
      str[j + 1] = str[j];
    }
    str[22] = '\n';
    for (int ii = 45; ii < 200; ii++)str[ii] = '\0';
    tft.print(str);

  } else {

    if (reboot == 0) {
      Serial.println("起動しました");
    }
    tft.print("No signal.");
  }




  unsigned long int now = micros() / 1000000;
  unsigned long int lim = now + 60;
  while (1) {
    str = Serial.readStringUntil(';');
    if (str[0] != '\0') {
      Serial.print("入力受付:"); Serial.println(str);
      break;
    }
    unsigned long int now = micros() / 1000000;
    if (now >= lim) {
      Serial.println("定期的な再起動を行います");
      reboot = 1;
      break;
    }
  }
}



unsigned long testLines(uint16_t color) {
  unsigned long start, t;
  int           x1, y1, x2, y2,
                w = tft.width(),
                h = tft.height();



  tft.fillScreen(BLACK);

  start = micros();
  switch (random(4)) {
    case 0:
      x1    = 0;
      y1    = h - 1;
      y2    = 0;
      for (x2 = 0; x2 < w; x2 += 9) tft.drawLine(x1, y1, x2, y2, color);
      x2    = w - 1;
      for (y2 = 0; y2 < h; y2 += 9) tft.drawLine(x1, y1, x2, y2, color);
      break;
    case 1:
      x1    = w - 1;
      y1    = 0;
      y2    = h - 1;
      for (x2 = w; x2 > 0; x2 -= 9) tft.drawLine(x1, y1, x2, y2, color);
      x2    = 0;
      for (y2 = h; y2 > 0; y2 -= 9) tft.drawLine(x1, y1, x2, y2, color);
      break;
    case 2:
      x1    = 0;
      y1    = 0;
      y2    = h - 1;
      for (x2 = 0; x2 < w; x2 += 9) tft.drawLine(x1, y1, x2, y2, color);
      x2    = w - 1;
      for (y2 = h; y2 > 0; y2 -= 9) tft.drawLine(x1, y1, x2, y2, color);
      break;
    case 3:
      x1    = w - 1;
      y1    = h - 1;
      y2    = 0;
      for (x2 = w; x2 > 0; x2 -= 9) tft.drawLine(x1, y1, x2, y2, color);
      x2    = 0;
      for (y2 = 0; y2 < h; y2 += 9) tft.drawLine(x1, y1, x2, y2, color);
      break;
  }

  t    += micros() - start;

  return micros() - start;
}

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

Please note that posts that do not contain Japanese are ignored. (Spam measures)コメントには日本語を含んでください。