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
- Committer:
- tyleralt
- Date:
- 2015-04-20
- Revision:
- 4:f81b40e04a58
- Parent:
- 3:1e9b4a4bf177
- Child:
- 5:6d8f9165021e
File content as of revision 4:f81b40e04a58:
#include "mbed.h" #include <vector> #define BUFFER_SIZE 16 #define NUMBER_OF_SLICES 90 //DigitalOut Pins DigitalOut pushRegister(p23); DigitalOut pushBit(p24); DigitalOut dataArmOne(p15); DigitalOut dataArmTwo(p16); DigitalOut dataArmThree(p17); DigitalOut dataArmFour(p18); DigitalOut dataArmFive(p19); DigitalOut dataArmSix(p20); DigitalOut dataArmSeven(p21); DigitalOut dataArmEight(p22); DigitalOut led(LED1); //Enable Interupt InterruptIn hallSensor(p25); //Set Up Timer and ticker Timer rotationTime; Ticker updateLeds; //Declare global vars double slice_time; double rotate_time; int current_slice; char slice_data [NUMBER_OF_SLICES][16]; //[slice][specific led distance] (0 is closest) & with approppriate bit for each arm double firstTime; Serial pc(USBTX, USBRX); // tx, rx Serial bt(p9, p10);// tx, rx void pushData (char bits [16]){ //pc.printf("got here"); //for (int i = 0; i < 16; i ++){ // pc.printf("%i %u ", i, bits[i]); // } for (int i = 8; i < 16; i ++){ dataArmOne = bits [i] & 0x01; dataArmTwo = bits [i] & 0x02; dataArmThree = bits [i]& 0x04; dataArmFour = bits [i]& 0x08; dataArmFive = bits [i] & 0x10; dataArmSix = bits [i] & 0x20; dataArmSeven = bits [i] & 0x40; dataArmEight = bits [i] & 0x80; pushBit = 1; pushBit = 0; } for (int i = 7; i >= 0; i --){ dataArmOne = bits [i] & 0x01; dataArmTwo = bits [i] & 0x02; dataArmThree = bits [i]& 0x04; dataArmFour = bits [i]& 0x08; dataArmFive = bits [i] & 0x10; dataArmSix = bits [i] & 0x20; dataArmSeven = bits [i] & 0x40; dataArmEight = bits [i] & 0x80; pushBit = 1; pushBit = 0; } pushRegister = 1; pushRegister = 0; } //periodic display interrupt void nextLedPush(){ if (current_slice < NUMBER_OF_SLICES){ pushData(slice_data[current_slice]); current_slice ++; } else { updateLeds.detach(); } } //Hall sensor interupt void rotate_sense(){ pc.printf("interupt"); if (firstTime){ rotationTime.reset(); rotationTime.start(); firstTime = 0; pc.printf("first time"); led = !led; return; } else if(current_slice < NUMBER_OF_SLICES / 4){ return; } pc.printf("seconod time \n"); led = !led; rotate_time = rotationTime.read_us(); rotationTime.reset(); rotationTime.start(); slice_time = (double) rotate_time/NUMBER_OF_SLICES; current_slice = 0; updateLeds.attach_us(&nextLedPush, slice_time); } int main() { pc.printf("started"); firstTime = 1; current_slice = 90; hallSensor.fall(&rotate_sense); for (int i = 0; i < 45; i ++){ slice_data [i][0] = 0x01; // bit 0 is high on arm 0 slice_data [i][1] = 0x00; slice_data [i][2] = 0x00; slice_data [i][3] = 0x00; slice_data [i][4] = 0x00; slice_data [i][5] = 0x00; slice_data [i][6] = 0x00; slice_data [i][9] = 0x00; slice_data [i][10] = 0x00; slice_data [i][11] = 0x00; slice_data [i][12] = 0x00; slice_data [i][13] = 0x00; slice_data [i][14] = 0x00; slice_data [i][15] = 0x00; //{1,1,1,1,0,0,0,0,1,1,1,0,0,0,1,0}; } for (int i = 45; i < 90; i++){ slice_data [i][0] = 0x00; // bit 0 is high on arm 0 slice_data [i][1] = 0x00; slice_data [i][2] = 0x00; slice_data [i][3] = 0x00; slice_data [i][4] = 0x00; slice_data [i][5] = 0x00; slice_data [i][6] = 0x00; slice_data [i][9] = 0x00; slice_data [i][10] = 0x00; slice_data [i][11] = 0x00; slice_data [i][12] = 0x00; slice_data [i][13] = 0x00; slice_data [i][14] = 0x00; slice_data [i][15] = 0x00; //{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; } pushData(slice_data[20]); while(1) { if (bt.readable()){ pc.printf("Just read %c", bt.getc()); } } }