#define TFT_CS 22
#define TFT_DC 5
#define TFT_MOSI 23
#define TFT_SCLK 18
#define FCS 13
#define FSCK 12
#define SO 14
// Created by Bodmer 24th Jan 2017
// The latest Arduino IDE versions support UTF-8 encoding of Unicode characters
// within sketches:
// https://playground.arduino.cc/Code/UTF-8
/*
The library expects strings to be in UTF-8 encoded format:
https://www.fileformat.info/info/unicode/utf8.htm
Creating varaibles needs to be done with care when using character arrays:
char c = 'µ'; // Wrong
char bad[4] = "5µA"; // Wrong
char good[] = "5µA"; // Good
String okay = "5µA"; // Good
This is because UTF-8 characters outside the basic Latin set occupy more than
1 byte per character! A 16 bit Unicode character occupies 3 bytes!
*/
// The fonts are stored in arrays within the sketch tabs.
// A processing sketch to create new fonts can be found in the Tools folder of TFT_eSPI
// https://github.com/Bodmer/TFT_eSPI/tree/master/Tools/Create_Smooth_Font/Create_font
#include "NotoSansBold15.h"
#include "Latin_Hiragana_24.h"
#include "Unicode_Test_72.h"
#include "Andalus24.h"
#include "CourierB24.h"
//====================================================================================
// Libraries
//====================================================================================
#include <TFT_eSPI.h> // Hardware-specific library
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
uint16_t bg = TFT_BLACK;
uint16_t fg = TFT_WHITE;
String fuses[]={"LPWSP","LHORN","LMIDB","LFILL","SUBFR","MOBDG",
"RPWSP","RHORN","RM1DB","RFILL","SUBRR","BXDSP"};
const int circleR = 12;
const int xOffset =170;
const int xOffset2 = 260;
const int yOffset= 35;
const int xStart = 10;
const int yStart = 55;
int xPos ;
int yPos;
float voltage;
bool fuseState[16];
//====================================================================================
// Setup
//====================================================================================
void setup()
{
Serial.begin(115200); // Used for messages and the C array generator
Serial.println("Starting..");
pinMode(FCS,OUTPUT);
pinMode(FSCK,OUTPUT);
pinMode(SO, INPUT_PULLUP);
tft.begin();
tft.setRotation(1); // portrait
tft.loadFont(CourierB24);
fg = TFT_WHITE;
bg = TFT_BLACK;
tft.fillRect(5,0,300,30,ILI9341_BLUE);
tft.setTextColor(ILI9341_YELLOW);
tft.setCursor(10, 20);
tft.println("FUSE STATUS ");
yPos = 0;
//tft.setTextSize(1);
tft.setTextColor(ILI9341_WHITE);
for(int i = 0;i<=5;i++){
tft.setCursor(xStart, yStart+yPos);
tft.println(fuses[i]);
tft.setCursor(xStart+xOffset, yStart+yPos);
tft.println(fuses[i+6]);
yPos +=yOffset;
}
}
//====================================================================================
// Loop
//====================================================================================
void loop()
{
yPos=yStart-6;
readFuses();
for(int i = 0;i<6;i++){
if(fuseState[i]==1)
tft.fillSmoothCircle(110, yPos, circleR, ILI9341_GREEN,ILI9341_GREEN);
else
tft.fillSmoothCircle(110, yPos, circleR, ILI9341_RED, ILI9341_RED);
if(fuseState[i+6]==1)
tft.fillCircle(270, yPos, circleR, ILI9341_GREEN);
else
tft.fillCircle(270, yPos, circleR, ILI9341_RED);
yPos +=yOffset;
}
tft.setCursor(230,20);
tft.setTextColor(ILI9341_WHITE);
//tft.println(analogRead(A5));
voltage=analogRead(A5)*5.0/1024;
tft.fillRect(230,0,90,30,ILI9341_BLUE);
tft.print(voltage);
tft.print("V");
Serial.println(voltage);
delay(500);
//
//----------------------------------------------------------------------------
}
//====================================================================================
void readFuses(){
digitalWrite(FCS,HIGH);
delay(1);
for(int i = 0; i<12;i++){
fuseState[i]=digitalRead(SO);
Serial.println(fuseState[i]);
digitalWrite(FSCK,HIGH);
delay(1);
digitalWrite(FSCK,LOW);
delay(1);
}
digitalWrite(FCS,LOW);
delay(1);
}