Last active
February 24, 2017 09:27
-
-
Save VioletGiraffe/ac831ea54931bb16a210e09f527b80d0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define TFT_RST 0 // you can also connect this to the Arduino reset, in which case, set this #define pin to 0! | |
#include "PDQ_ST7735_config.h" | |
#include <PDQ_FastPin.h> | |
#include <PDQ_ST7735.h> | |
#include <gfxfont.h> | |
#include <PDQ_GFX.h> | |
#include <TimerOne.h> | |
#include <StandardCplusplus.h> | |
#include <SPI.h> | |
#include <algorithm> | |
#include <math.h> | |
#define analogInPin A0 | |
uint16_t sample = 0, maxSampleValue = 0; | |
#ifndef _PDQ_ST7735H_ | |
Adafruit_ST7735 tft = Adafruit_ST7735(ST7735_CS_PIN, ST7735_DC_PIN, TFT_RST); | |
#else | |
PDQ_ST7735 tft; | |
#endif | |
void setup() { | |
// initialize serial communications at 9600 bps: | |
Serial.begin(9600); | |
while (!Serial); | |
// Use this initializer if you're using a 1.8" TFT | |
//tft.initR(INITR_BLACKTAB); // initialize a ST7735S chip, black tab | |
// Use this initializer (uncomment) if you're using a 1.44" TFT | |
tft.initR(ST7735_INITR_144GREENTAB); // initialize a ST7735S chip, black tab | |
tft.setTextSize(3); | |
tft.fillScreen(ST7735_BLACK); | |
tft.setCursor(0, 25); | |
tft.setTextSize(2); | |
tft.print("Max: "); | |
Timer1.initialize(100L * 1000L); // initialize timer1, 1/30th sec period | |
Timer1.attachInterrupt(updateScreen); | |
Serial.println("Initialized"); | |
} | |
template <typename T> void printNumber(T number, uint16_t color, bool newLineAfter = false) | |
{ | |
tft.setTextColor(color); | |
if (newLineAfter) | |
tft.println(number); | |
else | |
tft.print(number); | |
} | |
inline uint16_t RGB888_to_565(uint8_t R, uint8_t G, uint8_t B) | |
{ | |
return | |
(((R >> 3) & 0x1f) << 11) | | |
(((G >> 2) & 0x3f) << 6) | | |
(((B >> 3) & 0x1f) ); | |
} | |
void loop() { | |
// read the analog in value: | |
sample = analogRead(analogInPin); | |
maxSampleValue = std::max(maxSampleValue, sample); | |
// print the results to the serial monitor: | |
Serial.print("sensor = "); | |
Serial.println(maxSampleValue); | |
delay(1); | |
} | |
const auto textColor1 = RGB888_to_565(255, 235, 0); | |
const auto textColor2 = RGB888_to_565(255, 0, 200); | |
void updateScreen() | |
{ | |
tft.setTextSize(3); | |
tft.setCursor(0, 0); | |
printNumber(10, 0); | |
tft.setCursor(0, 0); | |
printNumber(10, textColor1); | |
tft.setTextSize(2); | |
tft.setCursor(70, 30); | |
printNumber(20, 0); | |
tft.setCursor(70, 30); | |
printNumber(20, textColor2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment