Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Sketch by GIOVANNI AGGIUSTATUTTO
- /*********************************************************************
- This is an example for our Monochrome OLEDs based on SSD1306 drivers
- Pick one up today in the adafruit shop!
- ------> http://www.adafruit.com/category/63_98
- This example is for a 128x64 size display using I2C to communicate
- 3 pins are required to interface (2 I2C and one reset)
- Adafruit invests time and resources providing this open source code,
- please support Adafruit and open-source hardware by purchasing
- products from Adafruit!
- Written by Limor Fried/Ladyada for Adafruit Industries.
- BSD license, check license.txt for more information
- All text above, and the splash screen must be included in any redistribution
- *********************************************************************/
- /*********************************************************************
- I change the adafruit SSD1306 to SH1106
- SH1106 driver don't provide several functions such as scroll commands.
- *********************************************************************/
- #include <SPI.h>
- #include <Wire.h>
- #include <Adafruit_GFX.h>
- #include <Adafruit_SH1106.h>
- #define OLED_RESET 4
- Adafruit_SH1106 display(OLED_RESET);
- const float circonferenza = 2.12;
- int rp5s = 0;
- float rTOT = 0;
- int kmh = 0;
- float m = 0;
- float km = 0;
- int b1;
- int b2;
- int b3;
- int b4;
- int b5;
- float battery = 0;
- bool led = false;
- void setup() {
- //Serial.begin(9600);
- pinMode(2, INPUT);
- pinMode(13, OUTPUT);
- // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
- display.begin(SH1106_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3D (for the 128x64)
- // init done
- // Show image buffer on the display hardware.
- // Since the buffer is intialized with an Adafruit splashscreen
- // internally, this will display the splashscreen.
- display.display();
- b1 = analogRead(A0);
- delay(100);
- b2 = analogRead(A0);
- delay(100);
- b3 = analogRead(A0);
- delay(100);
- b4 = analogRead(A0);
- delay(100);
- b5 = analogRead(A0);
- battery = (b1 + b2 + b3 + b4 + b5) / 5 * 5.0 / 1023;
- display.clearDisplay();
- delay(200);
- display.setTextSize(2);
- display.setTextColor(WHITE);
- display.setCursor(0, 0);
- display.println(" Ciao!");
- display.setTextSize(2);
- display.setTextColor(WHITE);
- display.setCursor(0, 25);
- display.println(" Batteria");
- display.setTextSize(2);
- display.setTextColor(WHITE);
- display.setCursor(0, 45);
- display.print(" ");
- display.print(battery);
- display.println(" V");
- display.display();
- delay(5000);
- // Clear the buffer.
- display.clearDisplay();
- }
- void loop() {
- attachInterrupt(digitalPinToInterrupt(2), function, RISING);
- delay(5000);
- detachInterrupt(2);
- kmh = (rp5s) / 5.0 * circonferenza * 3.6;
- m = (rTOT) * circonferenza;
- km = m / 1000.0;
- display.clearDisplay();
- display.setTextSize(2);
- display.setTextColor(WHITE);
- display.setCursor(0, 0);
- display.print(" ");
- display.print(kmh);
- display.println(" Km/h");
- display.setTextSize(2);
- display.setTextColor(WHITE);
- display.setCursor(0, 25);
- display.print(" ");
- display.print(km);
- display.println(" Km");
- display.setTextSize(2);
- display.setTextColor(WHITE);
- display.setCursor(0, 45);
- display.print(" ");
- display.print(millis() / 60000);
- display.println(" min");
- display.display();
- rp5s = 0;
- }
- void function() {
- rTOT = rTOT + 1.0;
- rp5s = rp5s + 1.0;
- //Serial.println(".");
- digitalWrite(13, led);
- led = !led;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement