[Arduino] wbBoxBench 試畫方塊
-
wbBoxBenchV2.ino
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <SPI.h>#define TFT_CS 15
#define TFT_DC 2
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC);void setup() {
tft.initR(INITR_GREENTAB);
tft.fillScreen(ST7735_BLACK);
uint16_t time = millis();
for(int i=0; i<500; i++) {
tft.fillRect(random(0,120), random(0,152), 8, 8, random(0,65536));
}
time = millis() - time;
tft.print(time);
pinMode(0, INPUT);
pinMode(5, INPUT);
}void loop() {
int key=analogRead(A0)/240;
if (key==1) key=2;
if (digitalRead(5)==0) key=1;
if (digitalRead(0)==0) key=3;
switch(key) {
case 2: tft.fillRect(random(0,120), random(0,152), 8, 8, random(0,65536)); break;
case 0: tft.drawLine(random(0,128), random(0,160), random(0,128), random(0,160), random(0,65536)); break;
case 1: tft.drawLine(random(0,128), random(0,160), 64, 80, random(0,65536)); break;
case 3: tft.drawLine(random(0,128), random(0,160), random(0,128), random(0,160), random(0,65536)); break;
case 4: tft.fillRect(random(0,112), random(0,144), 16,16, random(0,65536)); break;
}
}