![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Final code for our 4180 Drawing Robot!
Dependencies: 4DGL-uLCD-SE gCodeParser mbed
pen.h@2:ba15545a4ccf, 2014-04-30 (annotated)
- Committer:
- jford38
- Date:
- Wed Apr 30 16:40:10 2014 +0000
- Revision:
- 2:ba15545a4ccf
- Parent:
- 0:40576dfac535
Added Visual Studio Source files and README.; Alejandro.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jford38 | 0:40576dfac535 | 1 | #ifndef PEN_H |
jford38 | 0:40576dfac535 | 2 | #define PEN_H |
jford38 | 0:40576dfac535 | 3 | |
jford38 | 0:40576dfac535 | 4 | #include "mbed.h" |
jford38 | 0:40576dfac535 | 5 | |
jford38 | 0:40576dfac535 | 6 | class Pen { |
jford38 | 0:40576dfac535 | 7 | |
jford38 | 0:40576dfac535 | 8 | public: |
jford38 | 0:40576dfac535 | 9 | Pen(PinName p, float r); |
jford38 | 0:40576dfac535 | 10 | ~Pen(); |
jford38 | 0:40576dfac535 | 11 | |
jford38 | 0:40576dfac535 | 12 | void up(); |
jford38 | 0:40576dfac535 | 13 | void down(); |
jford38 | 0:40576dfac535 | 14 | void pos(float angle); |
jford38 | 0:40576dfac535 | 15 | |
jford38 | 0:40576dfac535 | 16 | private: |
jford38 | 0:40576dfac535 | 17 | PwmOut* pen_pin; |
jford38 | 0:40576dfac535 | 18 | float range; |
jford38 | 0:40576dfac535 | 19 | float up_range, down_range; |
jford38 | 0:40576dfac535 | 20 | |
jford38 | 0:40576dfac535 | 21 | }; |
jford38 | 0:40576dfac535 | 22 | |
jford38 | 0:40576dfac535 | 23 | Pen::Pen(PinName p, float r) { |
jford38 | 0:40576dfac535 | 24 | range = r; |
jford38 | 0:40576dfac535 | 25 | up_range = 1; |
jford38 | 0:40576dfac535 | 26 | down_range = 1+90.0/range; |
jford38 | 0:40576dfac535 | 27 | pen_pin = new PwmOut(p); |
jford38 | 0:40576dfac535 | 28 | pen_pin->period_ms(20); |
jford38 | 0:40576dfac535 | 29 | up(); |
jford38 | 0:40576dfac535 | 30 | } |
jford38 | 0:40576dfac535 | 31 | |
jford38 | 0:40576dfac535 | 32 | Pen::~Pen() { |
jford38 | 0:40576dfac535 | 33 | delete pen_pin; |
jford38 | 0:40576dfac535 | 34 | } |
jford38 | 0:40576dfac535 | 35 | |
jford38 | 0:40576dfac535 | 36 | // Go to angle in degrees |
jford38 | 0:40576dfac535 | 37 | inline void Pen::pos(float angle) { |
jford38 | 0:40576dfac535 | 38 | pen_pin->pulsewidth_ms(1+angle/range); |
jford38 | 0:40576dfac535 | 39 | } |
jford38 | 0:40576dfac535 | 40 | |
jford38 | 0:40576dfac535 | 41 | inline void Pen::up() { |
jford38 | 0:40576dfac535 | 42 | pen_pin->pulsewidth_ms(up_range); |
jford38 | 0:40576dfac535 | 43 | } |
jford38 | 0:40576dfac535 | 44 | |
jford38 | 0:40576dfac535 | 45 | inline void Pen::down() { |
jford38 | 0:40576dfac535 | 46 | pen_pin->pulsewidth_ms(down_range); |
jford38 | 0:40576dfac535 | 47 | } |
jford38 | 0:40576dfac535 | 48 | |
jford38 | 0:40576dfac535 | 49 | #endif |