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@0:d9730cf42ecc, 2015-04-07 (annotated)
- Committer:
- tyleralt
- Date:
- Tue Apr 07 22:55:57 2015 +0000
- Revision:
- 0:d9730cf42ecc
- Child:
- 1:ea12b9153c51
initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tyleralt | 0:d9730cf42ecc | 1 | #include "mbed.h" |
tyleralt | 0:d9730cf42ecc | 2 | |
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 | 0:d9730cf42ecc | 22 | //Set Up Timer |
tyleralt | 0:d9730cf42ecc | 23 | Timer rotationTime; |
tyleralt | 0:d9730cf42ecc | 24 | |
tyleralt | 0:d9730cf42ecc | 25 | //Declare global vars |
tyleralt | 0:d9730cf42ecc | 26 | int slice_time; |
tyleralt | 0:d9730cf42ecc | 27 | int rotate_time; |
tyleralt | 0:d9730cf42ecc | 28 | int current_slice; |
tyleralt | 0:d9730cf42ecc | 29 | int [NUMBER_OF_SLICES][8][BUFFER_SIZE] slice_data; //[slice][forSepcificArm][eachBit] |
tyleralt | 0:d9730cf42ecc | 30 | Ticker updateLeds; |
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 | 0:d9730cf42ecc | 36 | //Hall sensor interupt |
tyleralt | 0:d9730cf42ecc | 37 | void rotate_sense(){ |
tyleralt | 0:d9730cf42ecc | 38 | if (firstTime){ |
tyleralt | 0:d9730cf42ecc | 39 | rotationTime.reset(); |
tyleralt | 0:d9730cf42ecc | 40 | rotationTime.start(); |
tyleralt | 0:d9730cf42ecc | 41 | firstTime = 0; |
tyleralt | 0:d9730cf42ecc | 42 | } |
tyleralt | 0:d9730cf42ecc | 43 | rotate_time = rotationTime.read_us(); |
tyleralt | 0:d9730cf42ecc | 44 | rotationTime.reset(); |
tyleralt | 0:d9730cf42ecc | 45 | rotate_interrupt = 1; |
tyleralt | 0:d9730cf42ecc | 46 | rotationTime.start(); |
tyleralt | 0:d9730cf42ecc | 47 | |
tyleralt | 0:d9730cf42ecc | 48 | slice_time = rotate_time/NUMBER_OF_SLICES; |
tyleralt | 0:d9730cf42ecc | 49 | current_slice = 0; |
tyleralt | 0:d9730cf42ecc | 50 | updateLeds.attach(&nextLedPush, slice_time); |
tyleralt | 0:d9730cf42ecc | 51 | } |
tyleralt | 0:d9730cf42ecc | 52 | |
tyleralt | 0:d9730cf42ecc | 53 | void pushData (int [][] bits){ |
tyleralt | 0:d9730cf42ecc | 54 | for (int i = 0; i < bit [0].length; i ++){ |
tyleralt | 0:d9730cf42ecc | 55 | dataArmOne = bits [0][i]; |
tyleralt | 0:d9730cf42ecc | 56 | dataArmTwo = bits [1][i]; |
tyleralt | 0:d9730cf42ecc | 57 | dataArmThree = bits [2][i]; |
tyleralt | 0:d9730cf42ecc | 58 | dataArmFour = bits [3][i]; |
tyleralt | 0:d9730cf42ecc | 59 | dataArmFive = bits [4][i]; |
tyleralt | 0:d9730cf42ecc | 60 | dataArmSix = bits [5][i]; |
tyleralt | 0:d9730cf42ecc | 61 | dataArmSeven = bits [6][i]; |
tyleralt | 0:d9730cf42ecc | 62 | dataArmEight = bits [7][i]; |
tyleralt | 0:d9730cf42ecc | 63 | |
tyleralt | 0:d9730cf42ecc | 64 | clock = 1; |
tyleralt | 0:d9730cf42ecc | 65 | clock = 0; |
tyleralt | 0:d9730cf42ecc | 66 | } |
tyleralt | 0:d9730cf42ecc | 67 | } |
tyleralt | 0:d9730cf42ecc | 68 | |
tyleralt | 0:d9730cf42ecc | 69 | |
tyleralt | 0:d9730cf42ecc | 70 | //periodic display interrupt |
tyleralt | 0:d9730cf42ecc | 71 | void nextLedPush(){ |
tyleralt | 0:d9730cf42ecc | 72 | pushData(slice_data[current_slice]); |
tyleralt | 0:d9730cf42ecc | 73 | pushRegister = 1; |
tyleralt | 0:d9730cf42ecc | 74 | pushRegister = 0; |
tyleralt | 0:d9730cf42ecc | 75 | current_slice ++; |
tyleralt | 0:d9730cf42ecc | 76 | } |
tyleralt | 0:d9730cf42ecc | 77 | |
tyleralt | 0:d9730cf42ecc | 78 | int main() { |
tyleralt | 0:d9730cf42ecc | 79 | firstTime = 1; |
tyleralt | 0:d9730cf42ecc | 80 | |
tyleralt | 0:d9730cf42ecc | 81 | hallSensor.fall(&rotate_sense); |
tyleralt | 0:d9730cf42ecc | 82 | for (int i = 0; i < slice_data [0].length / 2; i ++){ |
tyleralt | 0:d9730cf42ecc | 83 | slice_data [i][0] = [1,1,1,1,0,0,0,0,1,1,1,0,0,0,1,0]; |
tyleralt | 0:d9730cf42ecc | 84 | } |
tyleralt | 0:d9730cf42ecc | 85 | for (int i = slice_data [0].length / 2; i < slice_data[0].length; i++){ |
tyleralt | 0:d9730cf42ecc | 86 | slice_data [i][0] = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]; |
tyleralt | 0:d9730cf42ecc | 87 | } |
tyleralt | 0:d9730cf42ecc | 88 | |
tyleralt | 0:d9730cf42ecc | 89 | while(1) { |
tyleralt | 0:d9730cf42ecc | 90 | //TODO: add in the ability to update the buffers |
tyleralt | 0:d9730cf42ecc | 91 | } |
tyleralt | 0:d9730cf42ecc | 92 | } |