Tyler Altenhofen / Mbed 2 deprecated TylerPOV

Dependencies:   mbed

Committer:
tyleralt
Date:
Tue Apr 21 01:49:44 2015 +0000
Revision:
5:6d8f9165021e
Parent:
4:f81b40e04a58
Child:
6:1d7d769b398d
pretty sure everything is working

Who changed what in which revision?

UserRevisionLine numberNew 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 2:554edc4b0cf2 18 DigitalOut led(LED1);
tyleralt 0:d9730cf42ecc 19
tyleralt 0:d9730cf42ecc 20 //Enable Interupt
tyleralt 0:d9730cf42ecc 21 InterruptIn hallSensor(p25);
tyleralt 0:d9730cf42ecc 22
tyleralt 1:ea12b9153c51 23 //Set Up Timer and ticker
tyleralt 0:d9730cf42ecc 24 Timer rotationTime;
tyleralt 1:ea12b9153c51 25 Ticker updateLeds;
tyleralt 0:d9730cf42ecc 26
tyleralt 0:d9730cf42ecc 27 //Declare global vars
tyleralt 2:554edc4b0cf2 28 double slice_time;
tyleralt 2:554edc4b0cf2 29 double rotate_time;
tyleralt 0:d9730cf42ecc 30 int current_slice;
tyleralt 4:f81b40e04a58 31 char slice_data [NUMBER_OF_SLICES][16]; //[slice][specific led distance] (0 is closest) & with approppriate bit for each arm
tyleralt 2:554edc4b0cf2 32 double firstTime;
tyleralt 0:d9730cf42ecc 33
tyleralt 0:d9730cf42ecc 34 Serial pc(USBTX, USBRX); // tx, rx
tyleralt 3:1e9b4a4bf177 35 Serial bt(p9, p10);// tx, rx
tyleralt 0:d9730cf42ecc 36
tyleralt 0:d9730cf42ecc 37
tyleralt 4:f81b40e04a58 38 void pushData (char bits [16]){
tyleralt 4:f81b40e04a58 39 for (int i = 8; i < 16; i ++){
tyleralt 4:f81b40e04a58 40 dataArmOne = bits [i] & 0x01;
tyleralt 4:f81b40e04a58 41 dataArmTwo = bits [i] & 0x02;
tyleralt 4:f81b40e04a58 42 dataArmThree = bits [i]& 0x04;
tyleralt 4:f81b40e04a58 43 dataArmFour = bits [i]& 0x08;
tyleralt 4:f81b40e04a58 44 dataArmFive = bits [i] & 0x10;
tyleralt 4:f81b40e04a58 45 dataArmSix = bits [i] & 0x20;
tyleralt 4:f81b40e04a58 46 dataArmSeven = bits [i] & 0x40;
tyleralt 4:f81b40e04a58 47 dataArmEight = bits [i] & 0x80;
tyleralt 1:ea12b9153c51 48
tyleralt 1:ea12b9153c51 49 pushBit = 1;
tyleralt 1:ea12b9153c51 50 pushBit = 0;
tyleralt 1:ea12b9153c51 51 }
tyleralt 4:f81b40e04a58 52 for (int i = 7; i >= 0; i --){
tyleralt 4:f81b40e04a58 53 dataArmOne = bits [i] & 0x01;
tyleralt 4:f81b40e04a58 54 dataArmTwo = bits [i] & 0x02;
tyleralt 4:f81b40e04a58 55 dataArmThree = bits [i]& 0x04;
tyleralt 4:f81b40e04a58 56 dataArmFour = bits [i]& 0x08;
tyleralt 4:f81b40e04a58 57 dataArmFive = bits [i] & 0x10;
tyleralt 4:f81b40e04a58 58 dataArmSix = bits [i] & 0x20;
tyleralt 4:f81b40e04a58 59 dataArmSeven = bits [i] & 0x40;
tyleralt 4:f81b40e04a58 60 dataArmEight = bits [i] & 0x80;
tyleralt 4:f81b40e04a58 61
tyleralt 4:f81b40e04a58 62 pushBit = 1;
tyleralt 4:f81b40e04a58 63 pushBit = 0;
tyleralt 4:f81b40e04a58 64 }
tyleralt 4:f81b40e04a58 65
tyleralt 4:f81b40e04a58 66 pushRegister = 1;
tyleralt 4:f81b40e04a58 67 pushRegister = 0;
tyleralt 1:ea12b9153c51 68 }
tyleralt 1:ea12b9153c51 69
tyleralt 1:ea12b9153c51 70
tyleralt 1:ea12b9153c51 71 //periodic display interrupt
tyleralt 1:ea12b9153c51 72 void nextLedPush(){
tyleralt 1:ea12b9153c51 73 if (current_slice < NUMBER_OF_SLICES){
tyleralt 4:f81b40e04a58 74 pushData(slice_data[current_slice]);
tyleralt 1:ea12b9153c51 75 current_slice ++;
tyleralt 2:554edc4b0cf2 76 } else {
tyleralt 2:554edc4b0cf2 77 updateLeds.detach();
tyleralt 1:ea12b9153c51 78 }
tyleralt 1:ea12b9153c51 79 }
tyleralt 1:ea12b9153c51 80
tyleralt 0:d9730cf42ecc 81 //Hall sensor interupt
tyleralt 0:d9730cf42ecc 82 void rotate_sense(){
tyleralt 3:1e9b4a4bf177 83 pc.printf("interupt");
tyleralt 0:d9730cf42ecc 84 if (firstTime){
tyleralt 0:d9730cf42ecc 85 rotationTime.reset();
tyleralt 0:d9730cf42ecc 86 rotationTime.start();
tyleralt 0:d9730cf42ecc 87 firstTime = 0;
tyleralt 3:1e9b4a4bf177 88 pc.printf("first time");
tyleralt 3:1e9b4a4bf177 89 led = !led;
tyleralt 2:554edc4b0cf2 90 return;
tyleralt 4:f81b40e04a58 91 } else if(current_slice < NUMBER_OF_SLICES / 4){
tyleralt 2:554edc4b0cf2 92 return;
tyleralt 2:554edc4b0cf2 93 }
tyleralt 3:1e9b4a4bf177 94 pc.printf("seconod time \n");
tyleralt 3:1e9b4a4bf177 95 led = !led;
tyleralt 0:d9730cf42ecc 96 rotate_time = rotationTime.read_us();
tyleralt 0:d9730cf42ecc 97 rotationTime.reset();
tyleralt 0:d9730cf42ecc 98 rotationTime.start();
tyleralt 0:d9730cf42ecc 99
tyleralt 2:554edc4b0cf2 100 slice_time = (double) rotate_time/NUMBER_OF_SLICES;
tyleralt 0:d9730cf42ecc 101 current_slice = 0;
tyleralt 2:554edc4b0cf2 102 updateLeds.attach_us(&nextLedPush, slice_time);
tyleralt 0:d9730cf42ecc 103 }
tyleralt 0:d9730cf42ecc 104
tyleralt 0:d9730cf42ecc 105
tyleralt 0:d9730cf42ecc 106 int main() {
tyleralt 3:1e9b4a4bf177 107 pc.printf("started");
tyleralt 0:d9730cf42ecc 108 firstTime = 1;
tyleralt 2:554edc4b0cf2 109 current_slice = 90;
tyleralt 0:d9730cf42ecc 110
tyleralt 3:1e9b4a4bf177 111 hallSensor.fall(&rotate_sense);
tyleralt 2:554edc4b0cf2 112 for (int i = 0; i < 45; i ++){
tyleralt 4:f81b40e04a58 113 slice_data [i][0] = 0x01; // bit 0 is high on arm 0
tyleralt 5:6d8f9165021e 114 slice_data [i][1] = 0x01;
tyleralt 5:6d8f9165021e 115 slice_data [i][2] = 0x01;
tyleralt 5:6d8f9165021e 116 slice_data [i][3] = 0x01;
tyleralt 5:6d8f9165021e 117 slice_data [i][4] = 0x01;
tyleralt 5:6d8f9165021e 118 slice_data [i][5] = 0x01;
tyleralt 5:6d8f9165021e 119 slice_data [i][6] = 0x01;
tyleralt 5:6d8f9165021e 120 slice_data [i][7] = 0x01;
tyleralt 5:6d8f9165021e 121 slice_data [i][8] = 0x01;
tyleralt 5:6d8f9165021e 122 slice_data [i][9] = 0x01;
tyleralt 5:6d8f9165021e 123 slice_data [i][10] = 0x01;
tyleralt 5:6d8f9165021e 124 slice_data [i][11] = 0x01;
tyleralt 5:6d8f9165021e 125 slice_data [i][12] = 0x01;
tyleralt 5:6d8f9165021e 126 slice_data [i][13] = 0x01;
tyleralt 5:6d8f9165021e 127 slice_data [i][14] = 0x01;
tyleralt 5:6d8f9165021e 128 slice_data [i][15] = 0x01;
tyleralt 0:d9730cf42ecc 129 }
tyleralt 2:554edc4b0cf2 130 for (int i = 45; i < 90; i++){
tyleralt 4:f81b40e04a58 131 slice_data [i][0] = 0x00; // bit 0 is high on arm 0
tyleralt 5:6d8f9165021e 132 slice_data [i][1] = 0x01;
tyleralt 4:f81b40e04a58 133 slice_data [i][2] = 0x00;
tyleralt 5:6d8f9165021e 134 slice_data [i][3] = 0x01;
tyleralt 4:f81b40e04a58 135 slice_data [i][4] = 0x00;
tyleralt 5:6d8f9165021e 136 slice_data [i][5] = 0x01;
tyleralt 4:f81b40e04a58 137 slice_data [i][6] = 0x00;
tyleralt 5:6d8f9165021e 138 slice_data [i][7] = 0x01;
tyleralt 5:6d8f9165021e 139 slice_data [i][8] = 0x00;
tyleralt 5:6d8f9165021e 140 slice_data [i][9] = 0x01;
tyleralt 4:f81b40e04a58 141 slice_data [i][10] = 0x00;
tyleralt 5:6d8f9165021e 142 slice_data [i][11] = 0x01;
tyleralt 4:f81b40e04a58 143 slice_data [i][12] = 0x00;
tyleralt 5:6d8f9165021e 144 slice_data [i][13] = 0x01;
tyleralt 4:f81b40e04a58 145 slice_data [i][14] = 0x00;
tyleralt 5:6d8f9165021e 146 slice_data [i][15] = 0x01;
tyleralt 0:d9730cf42ecc 147 }
tyleralt 0:d9730cf42ecc 148 while(1) {
tyleralt 3:1e9b4a4bf177 149 if (bt.readable()){
tyleralt 4:f81b40e04a58 150 pc.printf("Just read %c", bt.getc());
tyleralt 4:f81b40e04a58 151 }
tyleralt 4:f81b40e04a58 152
tyleralt 0:d9730cf42ecc 153 }
tyleralt 0:d9730cf42ecc 154 }