An fully working IMU-Filter and Sensor drivers for the 10DOF-Board over I2C. All in one simple class. Include, calibrate sensors, call read, get angles. (3D Visualisation code for Python also included) Sensors: L3G4200D, ADXL345, HMC5883, BMP085
LED/LED.cpp@0:3e7450f1a938, 2013-08-27 (annotated)
- Committer:
- maetugr
- Date:
- Tue Aug 27 17:37:06 2013 +0000
- Revision:
- 0:3e7450f1a938
before 10DOF class (only files already created)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
maetugr | 0:3e7450f1a938 | 1 | #include "LED.h" |
maetugr | 0:3e7450f1a938 | 2 | #include "mbed.h" |
maetugr | 0:3e7450f1a938 | 3 | |
maetugr | 0:3e7450f1a938 | 4 | LED::LED() : Led(LED1, LED2, LED3, LED4){ |
maetugr | 0:3e7450f1a938 | 5 | roller = 0; |
maetugr | 0:3e7450f1a938 | 6 | } |
maetugr | 0:3e7450f1a938 | 7 | |
maetugr | 0:3e7450f1a938 | 8 | void LED::shownumber(int number) { |
maetugr | 0:3e7450f1a938 | 9 | Led = number; |
maetugr | 0:3e7450f1a938 | 10 | } |
maetugr | 0:3e7450f1a938 | 11 | |
maetugr | 0:3e7450f1a938 | 12 | void LED::ride(int times = 1) { |
maetugr | 0:3e7450f1a938 | 13 | Led = 0; |
maetugr | 0:3e7450f1a938 | 14 | for (int j = 0; j < times; j++) { |
maetugr | 0:3e7450f1a938 | 15 | for(int i=0; i < 4; i++) { |
maetugr | 0:3e7450f1a938 | 16 | Led = 1 << i; |
maetugr | 0:3e7450f1a938 | 17 | wait(0.2); |
maetugr | 0:3e7450f1a938 | 18 | } |
maetugr | 0:3e7450f1a938 | 19 | } |
maetugr | 0:3e7450f1a938 | 20 | Led = 0; |
maetugr | 0:3e7450f1a938 | 21 | } |
maetugr | 0:3e7450f1a938 | 22 | |
maetugr | 0:3e7450f1a938 | 23 | void LED::roll(int times = 1) { |
maetugr | 0:3e7450f1a938 | 24 | Led = 0; |
maetugr | 0:3e7450f1a938 | 25 | for (int j = 0; j < (times*2); j++) { |
maetugr | 0:3e7450f1a938 | 26 | for(int roller = 1; roller <= 4; roller++) { |
maetugr | 0:3e7450f1a938 | 27 | tilt(roller); |
maetugr | 0:3e7450f1a938 | 28 | wait(0.1); |
maetugr | 0:3e7450f1a938 | 29 | } |
maetugr | 0:3e7450f1a938 | 30 | } |
maetugr | 0:3e7450f1a938 | 31 | roller = 0; |
maetugr | 0:3e7450f1a938 | 32 | Led = 0; |
maetugr | 0:3e7450f1a938 | 33 | } |
maetugr | 0:3e7450f1a938 | 34 | |
maetugr | 0:3e7450f1a938 | 35 | void LED::rollnext() { |
maetugr | 0:3e7450f1a938 | 36 | if (roller >= 4) |
maetugr | 0:3e7450f1a938 | 37 | roller = 0; |
maetugr | 0:3e7450f1a938 | 38 | roller++; |
maetugr | 0:3e7450f1a938 | 39 | tilt(roller); |
maetugr | 0:3e7450f1a938 | 40 | } |
maetugr | 0:3e7450f1a938 | 41 | |
maetugr | 0:3e7450f1a938 | 42 | void LED::tilt(int index) { |
maetugr | 0:3e7450f1a938 | 43 | Led = Led ^ (1 << (index-1)); //XOR |
maetugr | 0:3e7450f1a938 | 44 | } |
maetugr | 0:3e7450f1a938 | 45 | |
maetugr | 0:3e7450f1a938 | 46 | void LED::set(int index) { |
maetugr | 0:3e7450f1a938 | 47 | Led = Led | (1 << (index-1)); //OR |
maetugr | 0:3e7450f1a938 | 48 | } |
maetugr | 0:3e7450f1a938 | 49 | |
maetugr | 0:3e7450f1a938 | 50 | void LED::reset(int index) { |
maetugr | 0:3e7450f1a938 | 51 | Led = Led & ~(1 << (index-1)); //OR |
maetugr | 0:3e7450f1a938 | 52 | } |
maetugr | 0:3e7450f1a938 | 53 | |
maetugr | 0:3e7450f1a938 | 54 | int LED::check(int index) { |
maetugr | 0:3e7450f1a938 | 55 | return Led & (1 << (index-1)); |
maetugr | 0:3e7450f1a938 | 56 | } |
maetugr | 0:3e7450f1a938 | 57 | |
maetugr | 0:3e7450f1a938 | 58 | void LED::operator=(int value) { |
maetugr | 0:3e7450f1a938 | 59 | Led = value; |
maetugr | 0:3e7450f1a938 | 60 | } |