Back to Parent

// This #include statement was automatically added by the Particle IDE.
#include "Adafruit_GFX.h"
#include "Adafruit_SSD1306.h"

#define OLED_DC     D3
#define OLED_CS     D4
#define OLED_RESET  D5
Adafruit_SSD1306 display(OLED_DC, OLED_RESET, OLED_CS);

#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH  16

#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2




#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif

const int SW_pin = D0; // digital pin connected to switch output
const int X_pin = A0; // analog pin connected to X output

String value = "N/A";

int valueNum = -1;
int pushButton = -1;
int total = 0;
int finalTotal = 0;

void setup()   {
  Serial.begin(9600);
  Particle.variable("Savings",&finalTotal, INT);
  display.begin(SSD1306_SWITCHCAPVCC);


  display.display(); // show splashscreen
  delay(1000);
  display.clearDisplay();   // clears the screen and buffer
  
  pinMode(SW_pin, INPUT);
  digitalWrite(SW_pin, HIGH);
  pinMode(X_pin, INPUT);

}

void loop(){
  String a = "A---B";
  String b = a.substring(0);
  display.clearDisplay();
  display.setCursor(0,0);
  display.setTextColor(WHITE);
  display.setTextSize(4);
  valueNum = map(analogRead(X_pin), 2035,4094,0,20);
  total = valueNum + total;
  display.println(total);
  display.display();
  if(digitalRead(SW_pin) == 0) {
    if(total < 0) {
        total = 0;
    }
    finalTotal = total;
    display.println(finalTotal);
    display.display();
  }
  delay(500);
}
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0