![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Tests of linear stage
Dependencies: mbed C12832 app-board-Potentiometer-LCD USBDevice
main.cpp@1:8abaa664f287, 2021-09-07 (annotated)
- Committer:
- kstokely
- Date:
- Tue Sep 07 18:50:15 2021 +0000
- Revision:
- 1:8abaa664f287
- Parent:
- 0:abb6184fc121
First commit;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fchoco | 0:abb6184fc121 | 1 | #include "mbed.h" |
fchoco | 0:abb6184fc121 | 2 | #include "C12832.h" |
kstokely | 1:8abaa664f287 | 3 | #include "USBMouse.h" |
kstokely | 1:8abaa664f287 | 4 | |
kstokely | 1:8abaa664f287 | 5 | |
kstokely | 1:8abaa664f287 | 6 | |
kstokely | 1:8abaa664f287 | 7 | USBMouse mouse; |
kstokely | 1:8abaa664f287 | 8 | //BusIn joy(p15,p12,p13,p16); |
kstokely | 1:8abaa664f287 | 9 | BusIn Up(p15); |
kstokely | 1:8abaa664f287 | 10 | BusIn Down(p12); |
kstokely | 1:8abaa664f287 | 11 | BusIn Left(p13); |
kstokely | 1:8abaa664f287 | 12 | BusIn Right(p16); |
kstokely | 1:8abaa664f287 | 13 | DigitalIn fire(p14); |
kstokely | 1:8abaa664f287 | 14 | |
kstokely | 1:8abaa664f287 | 15 | DigitalOut r (p25); |
kstokely | 1:8abaa664f287 | 16 | DigitalOut step(p24); |
fchoco | 0:abb6184fc121 | 17 | |
fchoco | 0:abb6184fc121 | 18 | AnalogIn pot1(p19); |
fchoco | 0:abb6184fc121 | 19 | AnalogIn pot2(p20); |
fchoco | 0:abb6184fc121 | 20 | |
fchoco | 0:abb6184fc121 | 21 | C12832 lcd(p5, p7, p6, p8, p11); |
fchoco | 0:abb6184fc121 | 22 | |
kstokely | 1:8abaa664f287 | 23 | |
kstokely | 1:8abaa664f287 | 24 | |
fchoco | 0:abb6184fc121 | 25 | int main() |
fchoco | 0:abb6184fc121 | 26 | { |
kstokely | 1:8abaa664f287 | 27 | int max_speed = 10000; |
fchoco | 0:abb6184fc121 | 28 | int p1, p2; |
kstokely | 1:8abaa664f287 | 29 | int speed; |
kstokely | 1:8abaa664f287 | 30 | int dir; |
fchoco | 0:abb6184fc121 | 31 | lcd.set_auto_up(0); |
kstokely | 1:8abaa664f287 | 32 | |
kstokely | 1:8abaa664f287 | 33 | |
fchoco | 0:abb6184fc121 | 34 | while(true) { |
fchoco | 0:abb6184fc121 | 35 | p1 = pot1.read_u16(); |
fchoco | 0:abb6184fc121 | 36 | p2 = pot2.read_u16(); |
kstokely | 1:8abaa664f287 | 37 | |
kstokely | 1:8abaa664f287 | 38 | speed = p1 * max_speed / 0xffff; |
kstokely | 1:8abaa664f287 | 39 | |
fchoco | 0:abb6184fc121 | 40 | lcd.locate(0, 0); |
kstokely | 1:8abaa664f287 | 41 | lcd.printf("Speed : %3d", speed); |
fchoco | 0:abb6184fc121 | 42 | p1 = p1 * lcd.width() / 0xffff; |
fchoco | 0:abb6184fc121 | 43 | lcd.fillrect(0, 9, p1, 14, 1); |
fchoco | 0:abb6184fc121 | 44 | lcd.fillrect(p1 + 1, 9, lcd.width() - 1, 14, 0); |
fchoco | 0:abb6184fc121 | 45 | lcd.locate(0, 16); |
kstokely | 1:8abaa664f287 | 46 | |
kstokely | 1:8abaa664f287 | 47 | dir = p2 * 100 / 0xffff; |
kstokely | 1:8abaa664f287 | 48 | lcd.printf("Dir: %3d ", dir); |
fchoco | 0:abb6184fc121 | 49 | p2 = p2 * lcd.width() / 0xffff; |
fchoco | 0:abb6184fc121 | 50 | lcd.fillrect(0, 25, p2, 30, 1); |
fchoco | 0:abb6184fc121 | 51 | lcd.fillrect(p2 + 1, 25, lcd.width(), 30, 0); |
kstokely | 1:8abaa664f287 | 52 | |
fchoco | 0:abb6184fc121 | 53 | lcd.copy_to_lcd(); |
kstokely | 1:8abaa664f287 | 54 | |
kstokely | 1:8abaa664f287 | 55 | if( dir > 50 ) |
kstokely | 1:8abaa664f287 | 56 | { |
kstokely | 1:8abaa664f287 | 57 | r = 1; |
kstokely | 1:8abaa664f287 | 58 | } |
kstokely | 1:8abaa664f287 | 59 | else |
kstokely | 1:8abaa664f287 | 60 | { |
kstokely | 1:8abaa664f287 | 61 | r = 0; |
kstokely | 1:8abaa664f287 | 62 | } |
kstokely | 1:8abaa664f287 | 63 | |
kstokely | 1:8abaa664f287 | 64 | |
kstokely | 1:8abaa664f287 | 65 | if(fire) |
kstokely | 1:8abaa664f287 | 66 | { |
kstokely | 1:8abaa664f287 | 67 | while(fire) |
kstokely | 1:8abaa664f287 | 68 | { |
kstokely | 1:8abaa664f287 | 69 | step = 1; |
kstokely | 1:8abaa664f287 | 70 | wait( 1.0/ speed); |
kstokely | 1:8abaa664f287 | 71 | step = 0; |
kstokely | 1:8abaa664f287 | 72 | } |
kstokely | 1:8abaa664f287 | 73 | } |
kstokely | 1:8abaa664f287 | 74 | |
kstokely | 1:8abaa664f287 | 75 | if(Left) |
kstokely | 1:8abaa664f287 | 76 | { |
kstokely | 1:8abaa664f287 | 77 | while(Left) |
kstokely | 1:8abaa664f287 | 78 | { |
kstokely | 1:8abaa664f287 | 79 | } |
kstokely | 1:8abaa664f287 | 80 | for(int i=0; i< 200; i++) |
kstokely | 1:8abaa664f287 | 81 | { |
kstokely | 1:8abaa664f287 | 82 | step = 1; |
kstokely | 1:8abaa664f287 | 83 | wait(1.0/speed); |
kstokely | 1:8abaa664f287 | 84 | step = 0; |
kstokely | 1:8abaa664f287 | 85 | } |
kstokely | 1:8abaa664f287 | 86 | } |
kstokely | 1:8abaa664f287 | 87 | |
kstokely | 1:8abaa664f287 | 88 | |
kstokely | 1:8abaa664f287 | 89 | wait(0.001); |
kstokely | 1:8abaa664f287 | 90 | //wait(0.1); |
fchoco | 0:abb6184fc121 | 91 | } |
fchoco | 0:abb6184fc121 | 92 | } |