![](/media/cache/profiles/ae9962652ca72b43b47d23ca1a088f74.jpg.50x50_q85.jpg)
Program using the Touch Sensor and a Servo
main.cpp@0:b831c26b9a46, 2014-11-12 (annotated)
- Committer:
- icarobrito
- Date:
- Wed Nov 12 18:01:35 2014 +0000
- Revision:
- 0:b831c26b9a46
Program using the Touch Sensor and a Servo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
icarobrito | 0:b831c26b9a46 | 1 | /*Programa para acionamento de um servomotor |
icarobrito | 0:b831c26b9a46 | 2 | O servo motor funciona de 90º a -90º |
icarobrito | 0:b831c26b9a46 | 3 | Neste programa é feita a leitura do touch e é utilizada para a posição do servomotor |
icarobrito | 0:b831c26b9a46 | 4 | */ |
icarobrito | 0:b831c26b9a46 | 5 | #include "mbed.h" |
icarobrito | 0:b831c26b9a46 | 6 | #include "Servo.h" |
icarobrito | 0:b831c26b9a46 | 7 | #include "TSISensor.h" |
icarobrito | 0:b831c26b9a46 | 8 | |
icarobrito | 0:b831c26b9a46 | 9 | TSISensor touch; //declarando o objeto do touch |
icarobrito | 0:b831c26b9a46 | 10 | Servo servo(PTE29); //declarando o objeto do servomotor e o pino |
icarobrito | 0:b831c26b9a46 | 11 | |
icarobrito | 0:b831c26b9a46 | 12 | |
icarobrito | 0:b831c26b9a46 | 13 | |
icarobrito | 0:b831c26b9a46 | 14 | int main() { |
icarobrito | 0:b831c26b9a46 | 15 | float a=0; |
icarobrito | 0:b831c26b9a46 | 16 | servo.Enable(1000,20000); |
icarobrito | 0:b831c26b9a46 | 17 | while(1){ |
icarobrito | 0:b831c26b9a46 | 18 | a=touch.readPercentage(); |
icarobrito | 0:b831c26b9a46 | 19 | a=a*1000+1000; //Fórmula para equiparar as escalas do servomotor e do sensor touch |
icarobrito | 0:b831c26b9a46 | 20 | servo.SetPosition(a); |
icarobrito | 0:b831c26b9a46 | 21 | wait(1); |
icarobrito | 0:b831c26b9a46 | 22 | |
icarobrito | 0:b831c26b9a46 | 23 | |
icarobrito | 0:b831c26b9a46 | 24 | |
icarobrito | 0:b831c26b9a46 | 25 | } |
icarobrito | 0:b831c26b9a46 | 26 | } |
icarobrito | 0:b831c26b9a46 | 27 |