Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Transformacija coda Analog read arduino

[es] :: Elektronika :: Mikrokontroleri :: Transformacija coda Analog read arduino

[ Pregleda: 118 | Odgovora: 0 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

pajper1
Pavlovic Dragan
Zeleznice
Nis

Član broj: 192308
Poruke: 916
87.116.178.*



+9 Profil

icon Transformacija coda Analog read arduino06.04.2020. u 17:50 - pre 51 dana i 11h
Ovaj kod je ispravan i radi ali potrebno mi je da umesto promene calcFaktor to mogu da odradim analogno sa potenciometrom i promenom na A0 (Analog read ) kako to da odradim?

//1986 Porsche 944 Turbo Speedometer Calibrator

//Public Domain

//raw 944 transmission sensor signal must be processed by external schmitt trigger

//Schmitt trigger should bypass filer and pull-up resistor

//Use LM2940-10 with decoupling caps per datasheet to power Arduino in automotive setting

//Arduino Pin 7 supplies modified signal for speedometer



const int debounce = 2500;

const int speedometerPin = 7;

const int sensorPin = 3;

int pulseState = LOW;

volatile unsigned long currentMicros = 0;

volatile unsigned long previousMicros= 0;

volatile unsigned long currentSpeed = 0;

volatile unsigned long previousSpeed = 0;

volatile unsigned long interval = 0;

unsigned long modInterval = 0;

float calFactor = .91; // decrease to slow down speedometer

// calFactor of 1 makes no change to speedometer




void setup()

{

pinMode (13, OUTPUT);

pinMode(speedometerPin, OUTPUT);

pinMode(sensorPin, INPUT);

digitalWrite (sensorPin, HIGH);

attachInterrupt (1, iSr, FALLING);

}
void loop()

{

noInterrupts();

modInterval=interval;

interrupts();

currentMicros = micros();

if (currentMicros-previousSpeed<1000000)

{

if (currentMicros - previousMicros>((modInterval/2)/calFactor))

{ previousMicros = currentMicros;

if (pulseState == LOW) pulseState = HIGH; else pulseState = LOW;

digitalWrite(13, pulseState); //to blink onboard LED

digitalWrite(speedometerPin, pulseState);

}

}

}



void iSr()

{

currentSpeed=micros();

if (digitalRead(sensorPin)==LOW)

{

if ((currentSpeed - previousSpeed) > debounce)

{

interval = currentSpeed - previousSpeed;

previousSpeed=currentSpeed;

}

}

}
Dragan
 
Odgovor na temu

[es] :: Elektronika :: Mikrokontroleri :: Transformacija coda Analog read arduino

[ Pregleda: 118 | Odgovora: 0 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.