#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h> // https://github.com/adafruit/Adafruit-PCD8544-Nokia-5110-LCD-library/blob/master/
// Hardware SPI
// SCK 13
// DIN 11
Adafruit_PCD8544 display = Adafruit_PCD8544(5, 7, 6); // DC, CS, RST
// https://www.espboards.dev/tools/monochrome-bitmap-tool // monochrome 16x16 bitmap editor
static const unsigned char PROGMEM heart[] =
{ B00111100, B00111100,
B01000010, B01000010,
B10000001, B10000001,
B10000000, B00000001,
B10000000, B00000001,
B10000000, B00000001,
B10000000, B00000001,
B01000000, B00000010,
B01000000, B00000010,
B00100000, B00000100,
B00100000, B00000100,
B00010000, B00001000,
B00001000, B00010000,
B00000100, B00100000,
B00000010, B01000000,
B00000001, B10000000,
};
int x, y, oldX[60], oldY[60], start = 25, center = 33; // trace arrays
void setup() {
Serial.begin(9600); // start serial comms
display.begin(); // start display instance
display.clearDisplay(); // clears display buffer
display.display(); // show buffer
display.setTextSize(2);
oldX[0] = start; // place the first pixel
oldY[0] = center; // place the first pixel
Serial.print("(");
Serial.print(oldX[0]);
Serial.print(",");
Serial.print(oldY[0]);
Serial.println(")");
}
void loop() {
int offset = map(analogRead(A0), 0, 1023, -8, 8); // range
display.clearDisplay();
display.setCursor(5, 5);
display.print("PPM: ");
display.setCursor(50, 5);
if (offset >= 0)
display.print(" ");
display.print(offset);
display.drawBitmap(5, 25, heart, 16, 16, 1); // x, y, bitmap, sizeX, sizeY, color
if (x == 60) // new x
x = 0;
y = center + offset; // new y
// for (int i = 0; i < x; i++) { // count from start of trace to current x
// display.drawLine(oldX[x], oldY[x], x, y, BLACK);
Serial.print(x);
Serial.print(" (");
Serial.print(oldX[x]);
Serial.print(",");
Serial.print(oldY[x]);
Serial.print(")(");
Serial.print(x);
Serial.print(",");
Serial.print(y);
Serial.println(")");
oldX[x] = x; // store last value
oldY[x] = y;
// }
display.display(); // display the new trace
x++; // next x
delay(50);
}Loading
nokia-5110
nokia-5110