-
Notifications
You must be signed in to change notification settings - Fork 0
/
Controle_f.ino
42 lines (31 loc) · 1.03 KB
/
Controle_f.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const int PWMA = 10;
const int PWMB = 11;
const int pin_chR = A5;
int leitura; //R-"Roda"; P-"Pistola"
float PWM;
const float chRmax=1960, chRmed=1550, chRmin=1105; //Coletar em teste val. "Roda" - ATUALIZADOS
//const int chPmax=1975, chPmed=1560, chPmin=1120; //Coletar em teste val. "Pist."
void setup() {
pinMode(pin_chR, INPUT);
pinMode(PWMA, OUTPUT);
pinMode(PWMB, OUTPUT);
// Serial.begin(9600);
while(pulseIn(pin_chR, HIGH)==0);
delay(1);
// Serial.begin(9600);
}
void loop() {
//------------- Lê os canais
leitura=pulseIn(pin_chR, HIGH);
//------------- Executa saidas para as acoes
if(leitura>chRmed){ // =>>
PWM=250.0*((leitura-chRmed)/(chRmax-chRmed));
analogWrite(PWMA, 127+PWM/2);
analogWrite(PWMB, 127-PWM/2);
}
else{ // <<=
PWM=250.0*((leitura-chRmed)/(chRmin-chRmed));
analogWrite(PWMA, 127-PWM/2);
analogWrite(PWMB, 127+PWM/2);
}
}