Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define pinoInterrupcao 3
- #define NPINS 10
- #define RPM_MAX 10500
- int pins[NPINS]={A4,A5,2,4,5,6,7,8,9,10};
- long aux=0;
- void isr(){
- aux++;
- }
- void setup() {
- pinMode(pinoInterrupcao, INPUT);
- for(int i=0;i<NPINS;i++)
- pinMode(pins[i],OUTPUT);
- Serial.begin(115200);
- attachInterrupt(digitalPinToInterrupt(pinoInterrupcao),isr,RISING);
- }
- void set_rpm_bar(int r){
- int n= (RPM_MAX-100)/10;
- n=r/n;
- if(r<50)
- n=0;
- for(int i=0;(i<NPINS)&&(i<n);i++)
- digitalWrite(pins[i], HIGH);
- for(int i=(n);(i<NPINS);i++)
- digitalWrite(pins[i], LOW);
- }
- void loop() {
- long a = millis();
- while( (millis()-a) < 100 );
- float rpm = float(aux * 600);
- aux = 0;
- //Serial.println(rpm);
- set_rpm_bar(rpm);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement