sample test program with Ax12
Dependencies: AX12 C12832_lcd SerialHalfDuplex mbed
main.cpp@0:0069ce266807, 2014-06-20 (annotated)
- Committer:
- ppr2013G2
- Date:
- Fri Jun 20 06:36:14 2014 +0000
- Revision:
- 0:0069ce266807
- Child:
- 1:58dae564e9ff
sample test with LCD AX12;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ppr2013G2 | 0:0069ce266807 | 1 | #include "mbed.h" |
ppr2013G2 | 0:0069ce266807 | 2 | #include "AX12.h" |
ppr2013G2 | 0:0069ce266807 | 3 | #include "C12832_lcd.h" |
ppr2013G2 | 0:0069ce266807 | 4 | |
ppr2013G2 | 0:0069ce266807 | 5 | AnalogIn pot1(p19); |
ppr2013G2 | 0:0069ce266807 | 6 | C12832_LCD lcd; |
ppr2013G2 | 0:0069ce266807 | 7 | |
ppr2013G2 | 0:0069ce266807 | 8 | /*******************************/ |
ppr2013G2 | 0:0069ce266807 | 9 | /********mapping function*******/ |
ppr2013G2 | 0:0069ce266807 | 10 | /*convert old range to new range*/ |
ppr2013G2 | 0:0069ce266807 | 11 | /*******************************/ |
ppr2013G2 | 0:0069ce266807 | 12 | double map(double val, double b_min, double b_max, double a_min, double a_max) |
ppr2013G2 | 0:0069ce266807 | 13 | { |
ppr2013G2 | 0:0069ce266807 | 14 | return (val - b_max) * (a_min - a_max) / (b_min - b_max) + a_max; |
ppr2013G2 | 0:0069ce266807 | 15 | } |
ppr2013G2 | 0:0069ce266807 | 16 | |
ppr2013G2 | 0:0069ce266807 | 17 | int main() |
ppr2013G2 | 0:0069ce266807 | 18 | { |
ppr2013G2 | 0:0069ce266807 | 19 | AX12 myax12 (p9, p10, 2); //for LPC1768 |
ppr2013G2 | 0:0069ce266807 | 20 | int deg; |
ppr2013G2 | 0:0069ce266807 | 21 | while (1) { |
ppr2013G2 | 0:0069ce266807 | 22 | lcd.cls();//clear screen |
ppr2013G2 | 0:0069ce266807 | 23 | lcd.locate(40,3);//set locate |
ppr2013G2 | 0:0069ce266807 | 24 | lcd.printf("!Hello Ax12!"); |
ppr2013G2 | 0:0069ce266807 | 25 | lcd.line(0, 13, 128, 13, 1);//draw a line |
ppr2013G2 | 0:0069ce266807 | 26 | deg=(int)map(pot1*10.0, 0.0, 10.0, 0.0, 300.0 );//convert range |
ppr2013G2 | 0:0069ce266807 | 27 | lcd.locate(0,15);//set locate |
ppr2013G2 | 0:0069ce266807 | 28 | lcd.printf("Pos:%g,Temp:%g,Volt%g",myax12.GetPosition(),myax12.GetTemp(),myax12.GetVolts()); |
ppr2013G2 | 0:0069ce266807 | 29 | myax12.SetGoal(deg); // set ax12 go to deg |
ppr2013G2 | 0:0069ce266807 | 30 | wait(0.1); |
ppr2013G2 | 0:0069ce266807 | 31 | } |
ppr2013G2 | 0:0069ce266807 | 32 | } |