Bruno Allaire-Lemay
/
APP1test
df
Fork of APP1 by
SPIDisplayer.cpp@13:bb9669053eb3, 2017-01-16 (annotated)
- Committer:
- GaiSensei
- Date:
- Mon Jan 16 00:06:45 2017 +0000
- Revision:
- 13:bb9669053eb3
- Parent:
- 2:b8a20f7e2912
- Child:
- 21:a111be2582be
Create homemade_mbed functions; ; - Read bits; - Write bits; ; Sorry messy commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
GaiSensei | 2:b8a20f7e2912 | 1 | #include "SPIDisplayer.hpp" |
GaiSensei | 2:b8a20f7e2912 | 2 | |
GaiSensei | 2:b8a20f7e2912 | 3 | SPIDisplayer::SPIDisplayer(PinName mosi, PinName miso, PinName sclk, PinName ssel): |
GaiSensei | 2:b8a20f7e2912 | 4 | device(SPI(mosi, miso, sclk, ssel)), |
GaiSensei | 2:b8a20f7e2912 | 5 | pc(Serial(USBTX, USBRX)) |
GaiSensei | 2:b8a20f7e2912 | 6 | { |
GaiSensei | 2:b8a20f7e2912 | 7 | |
GaiSensei | 2:b8a20f7e2912 | 8 | } |
GaiSensei | 2:b8a20f7e2912 | 9 | |
GaiSensei | 2:b8a20f7e2912 | 10 | void SPIDisplayer::displayAngle(float angle) |
GaiSensei | 2:b8a20f7e2912 | 11 | { |
GaiSensei | 2:b8a20f7e2912 | 12 | char digits[6]; |
GaiSensei | 2:b8a20f7e2912 | 13 | snprintf(digits, sizeof digits, "%f", angle); |
GaiSensei | 2:b8a20f7e2912 | 14 | |
GaiSensei | 2:b8a20f7e2912 | 15 | if(digits[1] == '.') |
GaiSensei | 2:b8a20f7e2912 | 16 | { |
GaiSensei | 2:b8a20f7e2912 | 17 | device.write(0); |
GaiSensei | 2:b8a20f7e2912 | 18 | wait(0.001); |
GaiSensei | 2:b8a20f7e2912 | 19 | device.write((int)digits[0] - 48); |
GaiSensei | 2:b8a20f7e2912 | 20 | wait(0.001); |
GaiSensei | 2:b8a20f7e2912 | 21 | device.write((int)digits[2] - 48); |
GaiSensei | 2:b8a20f7e2912 | 22 | wait(0.001); |
GaiSensei | 2:b8a20f7e2912 | 23 | device.write((int)digits[3] - 48); |
GaiSensei | 2:b8a20f7e2912 | 24 | wait(0.001); |
GaiSensei | 2:b8a20f7e2912 | 25 | } |
GaiSensei | 2:b8a20f7e2912 | 26 | else |
GaiSensei | 2:b8a20f7e2912 | 27 | { |
GaiSensei | 2:b8a20f7e2912 | 28 | device.write((int)digits[0] - 48); |
GaiSensei | 2:b8a20f7e2912 | 29 | wait(0.001); |
GaiSensei | 2:b8a20f7e2912 | 30 | device.write((int)digits[1] - 48); |
GaiSensei | 2:b8a20f7e2912 | 31 | wait(0.001); |
GaiSensei | 2:b8a20f7e2912 | 32 | device.write((int)digits[3] - 48); |
GaiSensei | 2:b8a20f7e2912 | 33 | wait(0.001); |
GaiSensei | 2:b8a20f7e2912 | 34 | device.write((int)digits[4] - 48); |
GaiSensei | 2:b8a20f7e2912 | 35 | wait(0.001); |
GaiSensei | 2:b8a20f7e2912 | 36 | } |
GaiSensei | 2:b8a20f7e2912 | 37 | |
GaiSensei | 2:b8a20f7e2912 | 38 | device.write(DECIMAL_CONTROL_REGISTER); |
GaiSensei | 2:b8a20f7e2912 | 39 | wait(0.001); |
GaiSensei | 2:b8a20f7e2912 | 40 | device.write(FLOATING_POINT_DOT_POSITION); |
GaiSensei | 2:b8a20f7e2912 | 41 | wait(0.001); |
GaiSensei | 2:b8a20f7e2912 | 42 | } |
GaiSensei | 2:b8a20f7e2912 | 43 | |
GaiSensei | 2:b8a20f7e2912 | 44 | void SPIDisplayer::reset() |
GaiSensei | 2:b8a20f7e2912 | 45 | { |
GaiSensei | 2:b8a20f7e2912 | 46 | device.write(CLEAR_DISPLAY_REGISTER); |
GaiSensei | 2:b8a20f7e2912 | 47 | wait(0.001); |
GaiSensei | 2:b8a20f7e2912 | 48 | device.write(CURSOR_CONROL_REGISTER); |
GaiSensei | 2:b8a20f7e2912 | 49 | wait(0.001); |
GaiSensei | 2:b8a20f7e2912 | 50 | device.write(MOST_LEFT_DIGIT_POSITION); |
GaiSensei | 2:b8a20f7e2912 | 51 | wait(0.001); |
GaiSensei | 2:b8a20f7e2912 | 52 | } |