Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Arduino.h>
- #include <Wire.h>
- #include <Adafruit_SSD1306.h>// You may have to edit library for 128x64, //default is 128 x 32.
- #define OLED_WIDTH 128
- #define OLED_HEIGHT 64
- #define OLED_ADDR 0x3C // A very common address for these displays.
- // -------------------------------------------
- // Tachometer Arduino Using OLED 128x64
- // www.ardukode.blogspot.com
- // -------------------------------------------
- Adafruit_SSD1306 display(OLED_WIDTH, OLED_HEIGHT);
- float value=0;
- float rev=0;
- int rpm;
- int oldtime=0;
- int time;
- void isr(){ //interrupt service routine
- rev++;
- }
- void setup(){
- display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);
- display.clearDisplay();
- digitalWrite(2 ,HIGH);// Instead of using a pull up resistor //using pin number 2
- attachInterrupt(0,isr,RISING); //attaching the interrupt
- }
- void loop(){
- delay(2000);// 2 second delay
- detachInterrupt(0); //detaches the interrupt while calculating
- time=millis()-oldtime; //finds the time
- rpm=(rev/time)*60000; //calculates rpm
- oldtime=millis(); //saves the current time
- rev=0;
- display.clearDisplay();
- display.setTextSize(1);
- display.setTextColor(WHITE);
- display.setCursor(10, 0);// Vertical, Horizontal.
- display.println("Digital Tachometer");
- display.setTextSize(2);
- display.setTextColor(WHITE);
- display.setCursor(0, 25);// Vertical, Horizontal.
- display.println(rpm);
- display.setTextSize(2);
- display.setTextColor(WHITE);
- display.setCursor(85,25);
- display.println("RPM");
- display.setTextSize(1);
- display.setTextColor(WHITE);
- display.setCursor(0, 55);// Vertical, Horizontal.
- display.println("ardukode.blogspot.com");
- display.display();
- attachInterrupt(0,isr,RISING);
- }
- // avrdude -DV -patmega328p -Pnet:192.168.4.1:23 -carduino -b115200 -U flash:w:firmware.hex:I
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement