EXP11
Dependencies: Servo TextLCD mbed tsi_sensor
main.cpp@0:5a76060c4ab6, 2016-04-13 (annotated)
- Committer:
- rx5
- Date:
- Wed Apr 13 07:13:25 2016 +0000
- Revision:
- 0:5a76060c4ab6
EXP11
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rx5 | 0:5a76060c4ab6 | 1 | #include "mbed.h" |
rx5 | 0:5a76060c4ab6 | 2 | #include "Servo.h" |
rx5 | 0:5a76060c4ab6 | 3 | #include "tsi_sensor.h" |
rx5 | 0:5a76060c4ab6 | 4 | #include "TextLCD.h" |
rx5 | 0:5a76060c4ab6 | 5 | #define ELEC0 9 // Constant for KL25Z tsi |
rx5 | 0:5a76060c4ab6 | 6 | #define ELEC1 10 // Constant for KL25Z tsi |
rx5 | 0:5a76060c4ab6 | 7 | TextLCD lcd(D2, D3, D4, D5, D6, D7); // Initlize LCD PIN => RS, EN, Data4, Data5, Data6, Data7 |
rx5 | 0:5a76060c4ab6 | 8 | TSIAnalogSlider tsi(ELEC0, ELEC1, 40); // Initlize tsi Slider |
rx5 | 0:5a76060c4ab6 | 9 | Servo myservo(D8); // Initlize Servo motor |
rx5 | 0:5a76060c4ab6 | 10 | |
rx5 | 0:5a76060c4ab6 | 11 | int main() { |
rx5 | 0:5a76060c4ab6 | 12 | myservo.calibrate(0.001, 90.0); //caliberate servo for -90 to +90 (0-180) degree |
rx5 | 0:5a76060c4ab6 | 13 | lcd.cls(); // Clear LCD |
rx5 | 0:5a76060c4ab6 | 14 | lcd.locate(0,0); // cursor on Col=0, Raw=0 |
rx5 | 0:5a76060c4ab6 | 15 | lcd.printf("Experiment - 11"); // print startup message on LCD first Raw |
rx5 | 0:5a76060c4ab6 | 16 | lcd.locate(0,1); // cursor on Col=0, Raw=1 |
rx5 | 0:5a76060c4ab6 | 17 | lcd.printf("TSI LCD+SERVO"); // print startup message on LCD second Raw |
rx5 | 0:5a76060c4ab6 | 18 | wait(3.0); // wait 3 second to show startup message |
rx5 | 0:5a76060c4ab6 | 19 | while(1) |
rx5 | 0:5a76060c4ab6 | 20 | { |
rx5 | 0:5a76060c4ab6 | 21 | float slider_pos; |
rx5 | 0:5a76060c4ab6 | 22 | slider_pos = tsi.readPercentage(); // Read TSI Slider Position i.e 0.00 to 1.00 |
rx5 | 0:5a76060c4ab6 | 23 | myservo.write(slider_pos); // Write to servo as percentage |
rx5 | 0:5a76060c4ab6 | 24 | lcd.cls(); // Clear LCD |
rx5 | 0:5a76060c4ab6 | 25 | lcd.locate(0,0); // cursor on Col=0, Raw=0 |
rx5 | 0:5a76060c4ab6 | 26 | lcd.printf("Slider = %0.2f",slider_pos); //Print Slider TSI Value on LCD first line |
rx5 | 0:5a76060c4ab6 | 27 | lcd.locate(0,1); // cursor on Col=0, Raw=1 |
rx5 | 0:5a76060c4ab6 | 28 | lcd.printf("Servo = %0.2f",slider_pos*180.0); //Print Servo angle Value on LCD Second line |
rx5 | 0:5a76060c4ab6 | 29 | wait(0.01); |
rx5 | 0:5a76060c4ab6 | 30 | |
rx5 | 0:5a76060c4ab6 | 31 | } |
rx5 | 0:5a76060c4ab6 | 32 | } |