Matthias Grob
/
FlyBed2
My fully self designed first stable working Quadrocopter Software.
LED/LED.cpp@0:12950aa67f2a, 2013-09-02 (annotated)
- Committer:
- maetugr
- Date:
- Mon Sep 02 15:04:22 2013 +0000
- Revision:
- 0:12950aa67f2a
first commit of new version (only one axis for test until now); note: no more Ticker! (made problems because of interrupts)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
maetugr | 0:12950aa67f2a | 1 | #include "LED.h" |
maetugr | 0:12950aa67f2a | 2 | #include "mbed.h" |
maetugr | 0:12950aa67f2a | 3 | |
maetugr | 0:12950aa67f2a | 4 | LED::LED() : Led(LED1, LED2, LED3, LED4){ |
maetugr | 0:12950aa67f2a | 5 | roller = 0; |
maetugr | 0:12950aa67f2a | 6 | } |
maetugr | 0:12950aa67f2a | 7 | |
maetugr | 0:12950aa67f2a | 8 | void LED::shownumber(int number) { |
maetugr | 0:12950aa67f2a | 9 | Led = number; |
maetugr | 0:12950aa67f2a | 10 | } |
maetugr | 0:12950aa67f2a | 11 | |
maetugr | 0:12950aa67f2a | 12 | void LED::ride(int times = 1) { |
maetugr | 0:12950aa67f2a | 13 | Led = 0; |
maetugr | 0:12950aa67f2a | 14 | for (int j = 0; j < times; j++) { |
maetugr | 0:12950aa67f2a | 15 | for(int i=0; i < 4; i++) { |
maetugr | 0:12950aa67f2a | 16 | Led = 1 << i; |
maetugr | 0:12950aa67f2a | 17 | wait(0.2); |
maetugr | 0:12950aa67f2a | 18 | } |
maetugr | 0:12950aa67f2a | 19 | } |
maetugr | 0:12950aa67f2a | 20 | Led = 0; |
maetugr | 0:12950aa67f2a | 21 | } |
maetugr | 0:12950aa67f2a | 22 | |
maetugr | 0:12950aa67f2a | 23 | void LED::roll(int times = 1) { |
maetugr | 0:12950aa67f2a | 24 | Led = 0; |
maetugr | 0:12950aa67f2a | 25 | for (int j = 0; j < (times*2); j++) { |
maetugr | 0:12950aa67f2a | 26 | for(int roller = 1; roller <= 4; roller++) { |
maetugr | 0:12950aa67f2a | 27 | tilt(roller); |
maetugr | 0:12950aa67f2a | 28 | wait(0.1); |
maetugr | 0:12950aa67f2a | 29 | } |
maetugr | 0:12950aa67f2a | 30 | } |
maetugr | 0:12950aa67f2a | 31 | roller = 0; |
maetugr | 0:12950aa67f2a | 32 | Led = 0; |
maetugr | 0:12950aa67f2a | 33 | } |
maetugr | 0:12950aa67f2a | 34 | |
maetugr | 0:12950aa67f2a | 35 | void LED::rollnext() { |
maetugr | 0:12950aa67f2a | 36 | if (roller >= 4) |
maetugr | 0:12950aa67f2a | 37 | roller = 0; |
maetugr | 0:12950aa67f2a | 38 | roller++; |
maetugr | 0:12950aa67f2a | 39 | tilt(roller); |
maetugr | 0:12950aa67f2a | 40 | } |
maetugr | 0:12950aa67f2a | 41 | |
maetugr | 0:12950aa67f2a | 42 | void LED::tilt(int index) { |
maetugr | 0:12950aa67f2a | 43 | Led = Led ^ (1 << (index-1)); //XOR |
maetugr | 0:12950aa67f2a | 44 | } |
maetugr | 0:12950aa67f2a | 45 | |
maetugr | 0:12950aa67f2a | 46 | void LED::set(int index) { |
maetugr | 0:12950aa67f2a | 47 | Led = Led | (1 << (index-1)); //OR |
maetugr | 0:12950aa67f2a | 48 | } |
maetugr | 0:12950aa67f2a | 49 | |
maetugr | 0:12950aa67f2a | 50 | void LED::reset(int index) { |
maetugr | 0:12950aa67f2a | 51 | Led = Led & ~(1 << (index-1)); //OR |
maetugr | 0:12950aa67f2a | 52 | } |
maetugr | 0:12950aa67f2a | 53 | |
maetugr | 0:12950aa67f2a | 54 | int LED::check(int index) { |
maetugr | 0:12950aa67f2a | 55 | return Led & (1 << (index-1)); |
maetugr | 0:12950aa67f2a | 56 | } |
maetugr | 0:12950aa67f2a | 57 | |
maetugr | 0:12950aa67f2a | 58 | void LED::operator=(int value) { |
maetugr | 0:12950aa67f2a | 59 | Led = value; |
maetugr | 0:12950aa67f2a | 60 | } |