hello to everyone. i am sorry for my bad english but i will try the best. i work on motorcycle meter. i have found a spark plug circuit that worked and i have readings and i will fint a code that will works. i have correct readings and everything its good and stable. my problem is this. i want to display it more accurate and more fine to look. i mean i want to display seems rpm for example : 1000 after 1110 then 1120 then 1130 then 1140 etc. i want all the number to show in screen. with this i have its goes from 1000 to 1560 for example and i dont like it. its easy this? even 50 by 50 rpm i dont have problem to show.
the code is this. i have a oled screen. i think its better for fast update. please help me if you want.
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
#define SSD1306_LCDHEIGHT 64
#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif
int val ;
volatile byte half_revolutions;
unsigned int rpm;
unsigned long timeold;
void setup() {
attachInterrupt(0, rpm1, RISING); // the output from spark plug sensor
half_revolutions = 0;
rpm = 0;
timeold = 0;
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3D (for the 128x64)
Serial.begin(9600);
}
void loop() {
val = map(rpm, 0, 8000, 0, 100);
if (half_revolutions >= 20) {
//Update RPM every 20 counts, increase this for better RPM resolution,
//decrease for faster update
rpm = 30*1000/(millis() - timeold)*half_revolutions;
timeold = millis();
half_revolutions = 0;
}
display.clearDisplay();
drawPercentbar( 0, 16, 128, 15,p3);
text () ;
display.display();
p3 = val ;
delay(5);
}
void text () {
display.setCursor (0,0) ;
display.setTextSize(2);
display.setTextColor(WHITE);
display.print (rpm) ;
display.print (" RPM") ;
}
void drawPercentbar(int x,int y, int width,int height, int progress)
{
progress = progress > 100 ? 100 : progress;
progress = progress < 0 ? 0 :progress;
float bar = ((float)(width-4) / 100) * progress;
display.drawRect(x, y, width, height, WHITE);
display.fillRect(x+2, y+2, bar , height-4, WHITE);
if( height >= 15){
display.setCursor((width/2) -3, y+5 );
display.setTextSize(1);
display.setTextColor(WHITE);
if( progress >=50)
display.setTextColor(BLACK, WHITE);
display.print(progress);
display.print("%");
}
}
void rpm1()
{
half_revolutions++;
}