/* simulatore di fascia toracica per cardiofrequenzimetro * VERSIONE PER ATTINY85 / 16MHz * burst di 10ms, frequenza variabile da 40 a 170bpm tramite potenziometro * collegato al pin A1 * segnale portante a 5,4 kHz accordato con circuito LC (39mH/22nF) alimentato tramite H-bridge * * Arduino UNO ==> ATTiny * Pin 1 ==> Pin 6 * Pin 3 ==> Pin 2 * Input A1 ==> Pin 7 */ unsigned long previousMillis = 0; // will store last time Enable was updated int EnableState = LOW; const long OnTime = 10; long OffTime = 990; // valore iniziale f=60bpm void setup() { pinMode (1, OUTPUT); pinMode(3, OUTPUT); // segnale modulante OSCCAL -= 14; //calibrazione oscillatore interno // generazione portante 5,4 kHz TCCR1 = 0x94; OCR1C = 182; // 16.000.000/16/182=5,4 kHz } void loop() { int val = analogRead(A1); // lettura tensione potenziometro variabile da 0V a 5V OffTime = map(val,0,1023,1500,350); // reverse mapping, 0V => 40bpm ; 5V => 170bpm unsigned long currentMillis = millis(); if ((EnableState == HIGH) && (currentMillis - previousMillis >= OnTime)) //burst 10ms { EnableState = LOW; previousMillis = currentMillis; digitalWrite(3, EnableState); } else if ((EnableState == LOW) && (currentMillis - previousMillis >= OffTime)) // T = OffTime+OnTime { EnableState = HIGH; previousMillis = currentMillis; digitalWrite(3, EnableState); } }