-
Notifications
You must be signed in to change notification settings - Fork 0
/
Large-Microphone -Module_8LED_mini-sounbar_ST7735-MINI160x80.ino
70 lines (65 loc) · 1.76 KB
/
Large-Microphone -Module_8LED_mini-sounbar_ST7735-MINI160x80.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
#include <SPI.h>
#define TFT_RST -1
#define TFT_CS 12
#define TFT_DC 8
#define TFT_MOSI 11
#define TFT_SCLK 13
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
int sensorPin = A0;
int sensorValue = 0;
int percentage;
int ledPins[] = {2, 3, 4, 5, 6, 7, 9, 10};
int xPos = 0;
void setup(){
Serial.begin(9600);
tft.initR(INITR_MINI160x80);
tft.setRotation(3);
uint16_t time = millis();
tft.fillScreen(ST77XX_BLACK);
time = millis() - time;
testfastlines(ST77XX_YELLOW, ST77XX_BLUE);
tft.fillScreen(ST77XX_BLACK);
for(int i=0; i<8; i++){
pinMode(ledPins[i], OUTPUT);
digitalWrite(ledPins[i], LOW);
}
}
void testfastlines(uint16_t color1, uint16_t color2) {
tft.fillScreen(ST77XX_BLACK);
for (int16_t y=0; y < tft.height(); y+=5) {
tft.drawFastHLine(0, y, tft.width(), color1);
}
for (int16_t x=0; x < tft.width(); x+=5) {
tft.drawFastVLine(x, 0, tft.height(), color2);
}
}
void bar(uint16_t color, int height) {
static int prevXPos = 0;
if (xPos == 0 && prevXPos == tft.width() - 1) {
tft.fillScreen(ST77XX_BLACK);
}
tft.drawLine(prevXPos, 0, prevXPos+1, tft.height(), ST77XX_BLACK);
tft.drawLine(xPos, tft.height() - height, xPos, tft.height(), color);
prevXPos = xPos;
xPos++;
if(xPos >= tft.width()) {
xPos = 0;
}
}
void led() {
for(int i=0; i<8; i++){
if(percentage >= ((i+1)*12.5)){
digitalWrite(ledPins[i], HIGH);
} else {
digitalWrite(ledPins[i], LOW);
}
}
}
void loop(){
sensorValue = analogRead(sensorPin);
percentage = map(sensorValue, 229, 300, 0, tft.height());
led();
bar(ST77XX_YELLOW, percentage);
}