[Arduino] 顯示彩色照片的範例
-
這是測試顯示四張照片的範例。每個按鍵都會顯示一張不同的照片。
照片檔案在這裡:tsuyu*.h
主程式:wbPhotosV2.ino
/***************************************************
Photo Display Demo -- WiFiBoy for ArduinoPress any key to show different photos.
v1.0 -- Sep 28, 2016 tklua@wifiboy.org
****************************************************/#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <SPI.h>
#define TFT_CS 15
#define TFT_RST 0
#define TFT_DC 2Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
#include "tsuyu7.h"
#include "tsuyu8.h"
#include "tsuyu6.h"
#include "tsuyu5.h"int oldkey=4, key;
uint8_t *img;
uint16_t pbuf[20480];inline uint16_t swapcolor(uint16_t x) {
return (x << 11) | (x & 0x07E0) | (x >> 11);
}void setup(void) {
tft.initR(INITR_GREENTAB); // initialize a ST7735S chip, black tab
tft.fillScreen(ST7735_BLACK);
memcpy_P(pbuf, img5, 40960);
tft.setAddrWindow(0,0,127,159);
for(int n=0; n<160*128; n++) tft.pushColor(*(pbuf+n));
}void loop() {
key=analogRead(A0)/230;
if (key==1) key=2;
if (digitalRead(5)==0) key=1;
if (digitalRead(0)==0) key=3;
if (oldkey != key && key != 4) {
switch(key) {
case 0: memcpy_P(pbuf, img7, 40960); break;
case 1: memcpy_P(pbuf, img8, 40960); break;
case 2: memcpy_P(pbuf, img6, 40960); break;
case 3: memcpy_P(pbuf, img5, 40960); break;
}
tft.setAddrWindow(0,0,127,159);
for(int n=0; n<160*128; n++) tft.pushColor(*(pbuf+n));
}
oldkey = key;
delay(50);
}