Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp@1:ea12b9153c51, 2015-04-09 (annotated)
- Committer:
- tyleralt
- Date:
- Thu Apr 09 22:26:57 2015 +0000
- Revision:
- 1:ea12b9153c51
- Parent:
- 0:d9730cf42ecc
- Child:
- 2:554edc4b0cf2
doing everything with bits
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| tyleralt | 0:d9730cf42ecc | 1 | #include "mbed.h" |
| tyleralt | 1:ea12b9153c51 | 2 | #include <vector> |
| tyleralt | 0:d9730cf42ecc | 3 | #define BUFFER_SIZE 16 |
| tyleralt | 0:d9730cf42ecc | 4 | #define NUMBER_OF_SLICES 90 |
| tyleralt | 0:d9730cf42ecc | 5 | |
| tyleralt | 0:d9730cf42ecc | 6 | //DigitalOut Pins |
| tyleralt | 0:d9730cf42ecc | 7 | DigitalOut pushRegister(p23); |
| tyleralt | 0:d9730cf42ecc | 8 | DigitalOut pushBit(p24); |
| tyleralt | 0:d9730cf42ecc | 9 | |
| tyleralt | 0:d9730cf42ecc | 10 | DigitalOut dataArmOne(p15); |
| tyleralt | 0:d9730cf42ecc | 11 | DigitalOut dataArmTwo(p16); |
| tyleralt | 0:d9730cf42ecc | 12 | DigitalOut dataArmThree(p17); |
| tyleralt | 0:d9730cf42ecc | 13 | DigitalOut dataArmFour(p18); |
| tyleralt | 0:d9730cf42ecc | 14 | DigitalOut dataArmFive(p19); |
| tyleralt | 0:d9730cf42ecc | 15 | DigitalOut dataArmSix(p20); |
| tyleralt | 0:d9730cf42ecc | 16 | DigitalOut dataArmSeven(p21); |
| tyleralt | 0:d9730cf42ecc | 17 | DigitalOut dataArmEight(p22); |
| tyleralt | 0:d9730cf42ecc | 18 | |
| tyleralt | 0:d9730cf42ecc | 19 | //Enable Interupt |
| tyleralt | 0:d9730cf42ecc | 20 | InterruptIn hallSensor(p25); |
| tyleralt | 0:d9730cf42ecc | 21 | |
| tyleralt | 1:ea12b9153c51 | 22 | //Set Up Timer and ticker |
| tyleralt | 0:d9730cf42ecc | 23 | Timer rotationTime; |
| tyleralt | 1:ea12b9153c51 | 24 | Ticker updateLeds; |
| tyleralt | 0:d9730cf42ecc | 25 | |
| tyleralt | 0:d9730cf42ecc | 26 | //Declare global vars |
| tyleralt | 0:d9730cf42ecc | 27 | int slice_time; |
| tyleralt | 0:d9730cf42ecc | 28 | int rotate_time; |
| tyleralt | 0:d9730cf42ecc | 29 | int current_slice; |
| tyleralt | 1:ea12b9153c51 | 30 | int slice_data [NUMBER_OF_SLICES][8][BUFFER_SIZE]; //[slice][forSepcificArm][eachBit] |
| tyleralt | 0:d9730cf42ecc | 31 | int firstTime; |
| tyleralt | 0:d9730cf42ecc | 32 | |
| tyleralt | 0:d9730cf42ecc | 33 | Serial pc(USBTX, USBRX); // tx, rx |
| tyleralt | 0:d9730cf42ecc | 34 | |
| tyleralt | 0:d9730cf42ecc | 35 | |
| tyleralt | 1:ea12b9153c51 | 36 | void pushData (int (*bits) [8][BUFFER_SIZE]){ |
| tyleralt | 1:ea12b9153c51 | 37 | for (int i = 0; i < 8; i ++){ |
| tyleralt | 1:ea12b9153c51 | 38 | dataArmOne = *bits [0][i]; |
| tyleralt | 1:ea12b9153c51 | 39 | dataArmTwo = *bits [1][i]; |
| tyleralt | 1:ea12b9153c51 | 40 | dataArmThree = *bits [2][i]; |
| tyleralt | 1:ea12b9153c51 | 41 | dataArmFour = *bits [3][i]; |
| tyleralt | 1:ea12b9153c51 | 42 | // dataArmFive = *bits [4][i]; |
| tyleralt | 1:ea12b9153c51 | 43 | //dataArmSix = *bits [5][i]; |
| tyleralt | 1:ea12b9153c51 | 44 | //dataArmSeven = *bits [6][i]; |
| tyleralt | 1:ea12b9153c51 | 45 | //dataArmEight = *bits [7][i]; |
| tyleralt | 1:ea12b9153c51 | 46 | |
| tyleralt | 1:ea12b9153c51 | 47 | pushBit = 1; |
| tyleralt | 1:ea12b9153c51 | 48 | pushBit = 0; |
| tyleralt | 1:ea12b9153c51 | 49 | } |
| tyleralt | 1:ea12b9153c51 | 50 | } |
| tyleralt | 1:ea12b9153c51 | 51 | |
| tyleralt | 1:ea12b9153c51 | 52 | |
| tyleralt | 1:ea12b9153c51 | 53 | //periodic display interrupt |
| tyleralt | 1:ea12b9153c51 | 54 | void nextLedPush(){ |
| tyleralt | 1:ea12b9153c51 | 55 | if (current_slice < NUMBER_OF_SLICES){ |
| tyleralt | 1:ea12b9153c51 | 56 | pushData(&slice_data[current_slice]); |
| tyleralt | 1:ea12b9153c51 | 57 | pushRegister = 1; |
| tyleralt | 1:ea12b9153c51 | 58 | pushRegister = 0; |
| tyleralt | 1:ea12b9153c51 | 59 | current_slice ++; |
| tyleralt | 1:ea12b9153c51 | 60 | } |
| tyleralt | 1:ea12b9153c51 | 61 | } |
| tyleralt | 1:ea12b9153c51 | 62 | |
| tyleralt | 0:d9730cf42ecc | 63 | //Hall sensor interupt |
| tyleralt | 0:d9730cf42ecc | 64 | void rotate_sense(){ |
| tyleralt | 0:d9730cf42ecc | 65 | if (firstTime){ |
| tyleralt | 0:d9730cf42ecc | 66 | rotationTime.reset(); |
| tyleralt | 0:d9730cf42ecc | 67 | rotationTime.start(); |
| tyleralt | 0:d9730cf42ecc | 68 | firstTime = 0; |
| tyleralt | 0:d9730cf42ecc | 69 | } |
| tyleralt | 0:d9730cf42ecc | 70 | rotate_time = rotationTime.read_us(); |
| tyleralt | 0:d9730cf42ecc | 71 | rotationTime.reset(); |
| tyleralt | 0:d9730cf42ecc | 72 | rotationTime.start(); |
| tyleralt | 0:d9730cf42ecc | 73 | |
| tyleralt | 0:d9730cf42ecc | 74 | slice_time = rotate_time/NUMBER_OF_SLICES; |
| tyleralt | 0:d9730cf42ecc | 75 | current_slice = 0; |
| tyleralt | 0:d9730cf42ecc | 76 | updateLeds.attach(&nextLedPush, slice_time); |
| tyleralt | 0:d9730cf42ecc | 77 | } |
| tyleralt | 0:d9730cf42ecc | 78 | |
| tyleralt | 0:d9730cf42ecc | 79 | |
| tyleralt | 0:d9730cf42ecc | 80 | int main() { |
| tyleralt | 0:d9730cf42ecc | 81 | firstTime = 1; |
| tyleralt | 0:d9730cf42ecc | 82 | |
| tyleralt | 0:d9730cf42ecc | 83 | hallSensor.fall(&rotate_sense); |
| tyleralt | 1:ea12b9153c51 | 84 | for (int i = 0; i < 4; i ++){ |
| tyleralt | 1:ea12b9153c51 | 85 | slice_data [i][0][0] = 1; |
| tyleralt | 1:ea12b9153c51 | 86 | //{1,1,1,1,0,0,0,0,1,1,1,0,0,0,1,0}; |
| tyleralt | 0:d9730cf42ecc | 87 | } |
| tyleralt | 1:ea12b9153c51 | 88 | for (int i = 4; i < 8; i++){ |
| tyleralt | 1:ea12b9153c51 | 89 | slice_data [i][0][0] = 0; |
| tyleralt | 1:ea12b9153c51 | 90 | //{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; |
| tyleralt | 0:d9730cf42ecc | 91 | } |
| tyleralt | 0:d9730cf42ecc | 92 | |
| tyleralt | 0:d9730cf42ecc | 93 | while(1) { |
| tyleralt | 0:d9730cf42ecc | 94 | //TODO: add in the ability to update the buffers |
| tyleralt | 0:d9730cf42ecc | 95 | } |
| tyleralt | 0:d9730cf42ecc | 96 | } |