Advertisement
Guest User

Untitled

a guest
Apr 24th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.41 KB | None | 0 0
  1. #include <msp430.h>
  2. #include <stdio.h>
  3. #include <stdbool.h>
  4.  
  5.  
  6.  
  7.  
  8. /**
  9. * main.c
  10. */
  11. enum Mode{heartbeat, steps};
  12. enum Mode mode = heartbeat;
  13.  
  14. int numbers [10][5] = {{0, 31, 17, 31, 0}, {0, 9, 31, 1, 0}, {0, 23, 21, 29, 0}, {0, 21, 21, 31, 0}, {0, 28, 4, 31, 0}, {0, 19, 21, 23, 0},
  15. {0, 31, 21, 23, 0}, {0, 24, 16, 31, 0}, {0, 31, 21, 31, 0}, {0, 28, 20, 31, 0}};
  16.  
  17. //int bpm[3][5] = {{31, 21, 21, 10, 0}, {31, 20, 20, 28, 0}, {31, 8, 4, 8, 31}};
  18. //int steps[5][5] = {{8, 21, 21, 2, 0}, {16, 16, 31, 16, 16}, {31, 21, 21, 17, 0}, {31, 20, 20, 8, 0}, {8, 21, 21, 2, 0}};
  19. int heart[7] = {8, 28, 30, 15, 30, 28, 8};
  20. int shoe[9] = {3, 7, 7, 31, 31, 0, 21, 20, 16};
  21. int arrow[9] = {17, 10, 4, 17, 10, 4, 17, 10, 4};
  22.  
  23. static const int LED1 = 0x10;
  24. static const int LED2 = 0x20;
  25. static const int LED3 = 0x01;
  26. static const int LED4 = 0x02;
  27. static const int LED5 = 0x04;
  28.  
  29. // port 1 - 4(0x10)LED1 5(0x20)LED2
  30. // port 2 - 0(0x01)LED3 1(0x02)LED4 2(0x04)LED5
  31.  
  32.  
  33. //Function Prototypes
  34. void setup();//94
  35. void adc_Setup();//121
  36. void adc_Sample();//254
  37. void displayLine(int line);//348
  38. int getNumArrayIndex(char c);//378
  39. void displayNum(char c);//403
  40. void displayChar(char* c);//414
  41. void displayString(char* s);// 424
  42. void displayVal(int value);//433
  43. void getBPM();//178
  44. void msDelay (unsigned int msTime);//170
  45. void calibrate();//132
  46. void getSteps();//213
  47. int squareRoot(int n);//382
  48. void BPM(void);
  49. void printCharacters();
  50. void display(int letter);
  51. //TIMER0 INTERRUPT 268
  52. //BUTTON INTERRUPT 308
  53.  
  54.  
  55. // Variables for heartbeat
  56. int adc[8] = {0}; //Sets up an array of 1 integer for adc readings
  57. int timercount = 0; //Counter for number of timed interrupts
  58. int heartbeatcount = 0; //Counter for number of heartbeats
  59. int upperThreshold = 400; //Upper threshold for heartbeat reading
  60. int lowerThreshold = 400; //Lower threshold for heartbeat reading
  61. int peak = 530;
  62. bool readBeat = false; //flag that determines if we want to read heartbeat or not
  63.  
  64.  
  65. //variables for step counter
  66. int xval[15] = {0};
  67. int yval[15] = {0};
  68. int zval[15] = {0};
  69. int xavg = 443;
  70. int yavg = 493;
  71. int zavg = 833;
  72. int stepThreshold = 75;
  73. int stepFlag = 0;
  74. int stepTotal = 0;
  75. int getStepsInitFlag = 1;
  76. bool getStepsFlag = false;
  77.  
  78. //Other important variables
  79. int displayValue = 0; //Value to be displayed on leds
  80. int timerMode = 0;
  81. int prevValue = 0;
  82. int testFlag = 1;
  83. int testFlag2 = 1;
  84.  
  85. int CCR0Refill = 500;
  86.  
  87. // Global variable for timer to print char
  88. char charToPrint;
  89.  
  90. char printChar;
  91. int lineIndex = 0;
  92. int charIndex = 0;
  93. int waitFlag = 0;
  94. int heartPrintFlag = 0;
  95. int stepPrintFlag = 0;
  96. int charLen = 0;
  97. int iconCompleteFlag = 0;
  98. int iconFlag = 0;
  99.  
  100.  
  101. int main(void) {
  102. WDTCTL = WDTPW + WDTHOLD;
  103. if(CALBC1_1MHZ == 0xFF || CALDCO_1MHZ == 0xFF) {
  104. while(1);
  105. }
  106. setup();
  107. while(1){
  108. if (getStepsFlag){
  109. getSteps();
  110. }
  111. }
  112. }
  113.  
  114. // ADC10 interrupt service routine
  115. #pragma vector=ADC10_VECTOR
  116. __interrupt void ADC10_ISR(void)
  117. {
  118. __bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR)
  119. }
  120.  
  121. void setup() {
  122. BCSCTL1 = CALBC1_1MHZ;
  123. DCOCTL = CALDCO_1MHZ;
  124. P1DIR &= 0x00; //Reset dir and output
  125. P1OUT &= 0x00;
  126. P2DIR &= 0x00;
  127. P2OUT &= 0x00;
  128. adc_Setup(); //set up adc
  129. P1SEL = 0;
  130. P1DIR |= BIT4 + BIT5; //set leds as outputs and everything else as input
  131. P2SEL = 0;
  132. P2DIR |= BIT0 + BIT1 + BIT2;
  133. P1REN |= BIT3; // Enable internal pull-up/down resistors
  134. P1OUT |= BIT3; //Select pull-up mode for P1.3
  135. P1IE |= BIT3; // P1.3 interrupt enabled
  136. P1IES |= BIT3; // P1.3 Hi/lo edge
  137. P1IFG &= ~BIT3; // P1.3 IFG cleared
  138.  
  139. P1REN |= BIT2; // Enable internal pull-up/down resistors
  140. P1OUT |= BIT2; //Select pull-up mode for P1.3
  141. P1IE |= BIT2; // P1.3 interrupt enabled
  142. P1IES |= BIT2; // P1.3 Hi/lo edge
  143. P1IFG &= ~BIT2; // P1.3 IFG cleared
  144.  
  145. // testing ISR time
  146. P2DIR |= BIT5;
  147. P2OUT &= ~BIT5;
  148.  
  149. _BIS_SR(GIE); // Enter LPM0 w/ interrupt
  150. }
  151.  
  152. // ADC set-up function
  153. void adc_Setup()
  154. {
  155. ADC10CTL1 = CONSEQ_1 + INCH_7; // Go through multiple channels, A7 to A0
  156. ADC10CTL0 = ADC10SHT_2 + MSC + ADC10ON + ADC10IE; // Sample & Hold Time + ADC10 ON + Interrupt Enable
  157. ADC10DTC1 = 0x08; // 1 conversion
  158. ADC10AE0 |= 0xC3; // option select for heartbeat, x,y,z
  159. CCTL0 = CCIE; // CCR0 interrupt disabled
  160. TACTL = TASSEL_2 + MC_1 + ID_3; // SMCLK/8, upmode
  161. // CCR0 = 32000; // 0.5 Hz lower = fastur
  162. CCR0 = CCR0Refill; // ?? Hz
  163. }
  164.  
  165. void calibrate()
  166. {
  167.  
  168. int xsum = 0;
  169. int ysum = 0;
  170. int zsum = 0;
  171. int i = 0;
  172. for (i = 0; i < 15; i++)
  173. {
  174. if(i == 2) {
  175. P2OUT &= ~LED5;
  176. }
  177. if(i == 5) {
  178. P2OUT &= ~LED4;
  179. }
  180. if(i == 8) {
  181. P2OUT &= ~LED3;
  182. }
  183. if(i == 11) {
  184. P1OUT &= ~LED2;
  185. }
  186. if(i == 14) {
  187. P1OUT &= ~LED1;
  188. }
  189. adc_Sample();
  190. xval[i] = adc[1];
  191. xsum = xval[i] + xsum;
  192. yval[i] = adc[0];
  193. ysum = yval[i] + ysum;
  194. zval[i] = adc[6];
  195. zsum = zval[i] + zsum;
  196. }
  197.  
  198. xavg = xsum/15.0;
  199. yavg = ysum/15.0;
  200. zavg = zsum/15.0;
  201. }
  202.  
  203. //fixed timer delay function
  204. void msDelay (unsigned int msTime) {
  205. long counter;
  206. for (counter = 0; counter <= msTime; counter++) {
  207. _delay_cycles(16000000/16000);
  208. }
  209. }
  210.  
  211. //Getting heartbeat
  212. void getBPM()
  213. {
  214. bool heartbeatdetected = false;
  215. bool heartbeatFlag = false; //Boolean to see if a heartbeat value has surpassed the upper threshold or gone under the lower threshold
  216. readBeat = true;
  217. CCTL0 = CCIE; // CCR0 interrupt enabled
  218.  
  219. while(readBeat)
  220. {
  221. adc_Sample(); // Function call for adc_samp
  222. if(adc[0] > peak) { //check if peak value has been hit yet, if not set peak to current highest value
  223. peak = adc[0];
  224. }
  225. if((int)(peak*0.9) >= adc[0] && heartbeatFlag) { //if adc value is less than peak, peak has been hit
  226. if(peak > (int)(upperThreshold * 1.1) || peak < (int)(upperThreshold * 0.9)) {
  227. upperThreshold = (int)(peak * 0.90); //set upper threshold to 92% of peak
  228. lowerThreshold = (int)(upperThreshold * 0.80); //set lower threshold to 88% of upper threshold
  229. }
  230. }
  231.  
  232. if(adc[0] > upperThreshold && !heartbeatFlag) { //Check if heartbeat adc value is higher than upper threshold
  233. heartbeatcount++;
  234. heartbeatFlag = true; //Prevent other heartbeats to be recorded until adc goes under lower threshold
  235. }
  236. if(adc[0] <= lowerThreshold && heartbeatFlag) { //Check if heartbeat adc value is lower than lower threshold
  237. heartbeatFlag = false; //Allow heartbeats to be recorded again
  238. peak = 0;
  239. }
  240. }
  241. heartbeatcount = 0;
  242. timercount = 0;
  243. // CCTL0 = ~CCIE; // CCR0 interrupt disabled
  244. }
  245.  
  246. //Getting steps
  247. void getSteps() {
  248. int acc=0;
  249. int totvect = 0;
  250. int totave = 0;
  251. int xaccl = 0;
  252. int yaccl = 0;
  253. int zaccl = 0;
  254. int i = 0;
  255. int xsquare, ysquare, zsquare, squareTot = 0;
  256.  
  257.  
  258. // while(1) {
  259. adc_Sample();
  260. xaccl = adc[1];
  261. yaccl = adc[0];
  262. zaccl = adc[6];
  263.  
  264. xsquare = (xaccl - xavg)* (xaccl - xavg);
  265. ysquare = (yaccl - yavg)*(yaccl - yavg);
  266. zsquare = (zaccl - zavg)*(zaccl - zavg);
  267. squareTot = xsquare + ysquare + zsquare;
  268.  
  269.  
  270. totave = squareRoot(squareTot);
  271. //cal steps
  272.  
  273. if (totave > stepThreshold && stepFlag == 0) {
  274. stepTotal = stepTotal + 1;
  275. stepFlag = 1;
  276. }
  277. // else if (totave > stepThreshold && stepFlag == 1) {
  278. //
  279. // }
  280. if (totave < stepThreshold && stepFlag == 1) {
  281. stepFlag = 0;
  282. }
  283. if(mode == steps) {
  284. displayValue = stepTotal;
  285. // char str[5];
  286. // sprintf(str, "%d", displayValue);
  287. // chartoprint = displayValue[0];
  288. }
  289. // }
  290. }
  291.  
  292.  
  293. // ADC sample conversion function
  294. void adc_Sample()
  295. {
  296. __bic_SR_register(GIE);// Low Power Mode 0, ADC10_ISR
  297. ADC10CTL0 &= ~ENC; // Disable Conversion
  298. while (ADC10CTL1 & BUSY); // Wait if ADC10 busy
  299. ADC10SA = (int)adc; // Transfers data to next array (DTC auto increments address)
  300. ADC10CTL0 |= ENC + ADC10SC; // Enable Conversion and conversion start
  301. // __bis_SR_register(CPUOFF + GIE);// Low Power Mode 0, ADC10_ISR
  302. __bis_SR_register(GIE);// Low Power Mode 0, ADC10_ISR
  303.  
  304. }
  305.  
  306. void printCharacters(){
  307. // need to set this to be done only after 3000
  308. int charLen;
  309. if(waitFlag > 0){
  310. waitFlag--;
  311. P1OUT &= ~(LED1 + LED2);
  312. P2OUT &= ~(LED3 + LED4 + LED5);
  313. return;
  314. }
  315. char str[5];
  316. if(mode == steps && iconFlag == 1){
  317. charLen = 9;
  318. display(arrow[lineIndex]);
  319. if(lineIndex == charLen - 1){
  320. iconCompleteFlag = 1;
  321. }
  322. }
  323. else if(mode == heartbeat && iconFlag == 1){
  324. charLen = 7;
  325. display(heart[lineIndex]);
  326. if(lineIndex == charLen - 1) {
  327. iconCompleteFlag = 1;
  328. }
  329. }
  330. else{
  331. charLen = 5;
  332. }
  333. sprintf(str, "%d", displayValue);
  334. if(charIndex < strlen(str)){
  335. charToPrint = str[charIndex];
  336. }
  337.  
  338. if(!iconFlag) {
  339. int num = getNumArrayIndex(charToPrint);
  340. display(numbers[num][lineIndex]);
  341. }
  342.  
  343. lineIndex += 1;
  344.  
  345. lineIndex = lineIndex % charLen;
  346. if(charIndex >= strlen(str) && iconCompleteFlag == 1){ // do we need the charIndex >= strlen(str) ??
  347. charIndex = 0;
  348. lineIndex = 0;
  349. iconFlag = 0;
  350. iconCompleteFlag = 0;
  351. if (mode == heartbeat){
  352. waitFlag = 3;
  353. }
  354. else{
  355. waitFlag = 5;
  356. }
  357. }
  358. else if(lineIndex == 0){
  359. charIndex++;
  360. charToPrint = str[charIndex];
  361. waitFlag = 1;
  362.  
  363. }
  364. if(charIndex >= strlen(str)) {
  365. iconFlag = 1;
  366. }
  367.  
  368.  
  369. }
  370. #pragma vector=TIMER0_A0_VECTOR
  371. __interrupt void Timer_A(void){
  372. // int oldbuttonstate = 0;
  373. //
  374. // int buttonstate;
  375. //
  376. //
  377. // buttonstate = !(P1IN & BIT3);
  378. //
  379. // if( (buttonstate != oldbuttonstate)) {
  380. // CCTL0 = ~CCIE;
  381. // }
  382. // if(P1IN&BIT3 != 0) {
  383. // CCTL0 = ~CCIE;
  384. // }
  385.  
  386. //testing ISR time begin
  387. P2OUT ^= BIT5;
  388. P2OUT ^= BIT5;
  389. P2OUT |= BIT5;
  390.  
  391. testFlag = P1IN&BIT3;
  392. testFlag2 = P1IN&BIT2;
  393. if(testFlag != 0) {
  394. // msDelay(1);
  395. testFlag = P1IN&BIT3;
  396. if(testFlag != 0){
  397. CCTL0 = ~CCIE;
  398. testFlag = 0;
  399.  
  400. if(mode == heartbeat) {
  401. P1OUT &= 0x00;
  402. P2OUT &= ~(BIT0 + BIT1 + BIT2);
  403. msDelay(1000);
  404. P1OUT |= LED1;
  405. msDelay(1000);
  406. P1OUT |= LED2;
  407. msDelay(1000);
  408. P2OUT |= LED3;
  409. msDelay(1000);
  410. P2OUT |= LED4;
  411. msDelay(1000);
  412. P2OUT |= LED5;
  413. P1IFG &= ~BIT3; // P1.3 IFG cleared
  414. // CCR0 = 32000;
  415. CCR0 = CCR0Refill;
  416. timerMode = 1;
  417. getBPM();
  418. testFlag = 0;
  419. testFlag2 = 0;
  420. }
  421. if(mode == steps) {
  422. P1OUT &= ~(LED1 + LED2);
  423. P2OUT &= ~(LED3 + LED4 + LED5);
  424. msDelay(400);
  425. P1OUT |= LED1;
  426. msDelay(400);
  427. P1OUT |= LED2;
  428. msDelay(400);
  429. P2OUT |= LED3;
  430. msDelay(400);
  431. P2OUT |= LED4;
  432. msDelay(400);
  433. P2OUT |= LED5;
  434. P1IFG &= ~BIT3;
  435. // calibrate();
  436. getStepsFlag = !getStepsFlag;
  437. testFlag = 0;
  438. testFlag2 = 0;
  439. CCTL0 = CCIE;
  440. }
  441. }
  442. }
  443.  
  444. else if(testFlag2 != 0) {
  445. // msDelay(1);
  446. testFlag2 = P1IN&BIT2;
  447. if(testFlag2 != 0){
  448.  
  449. if(mode == heartbeat) {
  450. mode = steps;
  451. }
  452. else {
  453. mode = heartbeat;
  454. }
  455. P1OUT &= 0x00;
  456. P2OUT &= ~(BIT0 + BIT1 + BIT2);
  457. msDelay(100);
  458. P1OUT |= LED1;
  459. msDelay(100);
  460. P1OUT |= LED2;
  461. msDelay(100);
  462. P2OUT |= LED3;
  463. msDelay(100);
  464. P2OUT |= LED4;
  465. msDelay(100);
  466. P2OUT |= LED5;
  467. P1IFG &= ~BIT2; // P1.3 IFG cleared
  468. testFlag = 0;
  469. testFlag2 = 0;
  470. int temp = displayValue;
  471. displayValue = prevValue;
  472. char str[5];
  473. sprintf(str, "%d", displayValue);
  474. charToPrint = str[0];
  475. prevValue = temp;
  476. }
  477. }
  478. if(timerMode == 1){
  479. if(readBeat) {
  480. timercount++; //Increment timer interrupt count ever half second, 20 is 10 seconds
  481. if(timercount == 500) { //Turn off leds accordingly
  482. P2OUT &= ~LED5;
  483. }
  484. if(timercount == 1000) {
  485. P2OUT &= ~LED4;
  486. }
  487. if(timercount == 1500) {
  488. P2OUT &= ~LED3;
  489. }
  490. if(timercount == 2000) {
  491. P1OUT &= ~LED2;
  492. }
  493. if(timercount == 2500) {
  494. P1OUT &= ~LED1;
  495. }
  496.  
  497. if(timercount >= 2500) { //If timer count is equal to or over 40, display value
  498. if(heartbeatcount >= 9) {
  499. displayValue = heartbeatcount * 6; //Set display value to be 6x the heartbeat count
  500. readBeat = false;
  501. // CCR0 = 32000;
  502. CCR0 = CCR0Refill;
  503. timerMode = 0;
  504. }
  505. heartbeatcount = 0; //Reset counters
  506. timercount = 0;
  507. if(readBeat) {
  508. P1OUT |= LED1 + LED2;
  509. msDelay(1000);
  510. P2OUT |= LED3 + LED4 + LED5;
  511. msDelay(1000);
  512. }
  513. //if readbeat is still true, set all 5 leds on again
  514. }
  515. }
  516. }
  517. if(timerMode == 0) {
  518. printCharacters();
  519. }
  520.  
  521. // testing ISR time end
  522. // P1OUT &= ~BIT4;
  523.  
  524. }
  525.  
  526.  
  527.  
  528. void display(int letter){
  529. displayLine(letter);
  530.  
  531. }
  532.  
  533. void BPM (void)
  534. {
  535.  
  536. }
  537.  
  538. //#pragma vector=PORT1_VECTOR
  539. //__interrupt void Port_1 (void)
  540. //{
  541. //
  542. //// if(P1IN&BIT3 == 0) {
  543. // if(mode == heartbeat) {
  544. // testFlag = 1;
  545. // P1OUT &= 0x00;
  546. // P2OUT &= 0x00;
  547. // msDelay(1000);
  548. // P1OUT |= LED1;
  549. // msDelay(1000);
  550. // P1OUT |= LED2;
  551. // msDelay(1000);
  552. // P2OUT |= LED3;
  553. // msDelay(1000);
  554. // P2OUT |= LED4;
  555. // msDelay(1000);
  556. // P2OUT |= LED5;
  557. // P1IFG &= ~BIT3; // P1.3 IFG cleared
  558. // CCR0 = 32000;
  559. // timerMode = 1;
  560. // getBPM();
  561. // testFlag = 1;
  562. // }
  563. // if(mode == steps) {
  564. // P1OUT &= 0x00;
  565. // P2OUT &= 0x00;
  566. // msDelay(400);
  567. // P1OUT |= LED1;
  568. // msDelay(400);
  569. // P1OUT |= LED2;
  570. // msDelay(400);
  571. // P2OUT |= LED3;
  572. // msDelay(400);
  573. // P2OUT |= LED4;
  574. // msDelay(400);
  575. // P2OUT |= LED5;
  576. // P1IFG &= ~BIT3;
  577. // calibrate();
  578. // }
  579. //// }
  580. //// else {
  581. //// mode++;
  582. //// P1OUT &= 0x00;
  583. //// P2OUT &= 0x00;
  584. //// msDelay(100);
  585. //// P1OUT |= LED1;
  586. //// msDelay(100);
  587. //// P1OUT |= LED2;
  588. //// msDelay(100);
  589. //// P2OUT |= LED3;
  590. //// msDelay(100);
  591. //// P2OUT |= LED4;
  592. //// msDelay(100);
  593. //// P2OUT |= LED5;
  594. //// P1IFG &= ~BIT2; // P1.3 IFG cleared
  595. //// int temp = displayValue;
  596. //// displayValue = prevValue;
  597. //// prevValue = temp;
  598. //// }
  599. //}
  600.  
  601. void displayLine(int line) {
  602. int finalPort1 = 0;
  603. int finalPort2 = 0;
  604. int myline = 0;
  605. myline = line;
  606.  
  607. if(myline >= 16) {
  608. P1OUT |= LED1;
  609. myline -= 16;
  610. }
  611. else{
  612. P1OUT &= ~LED1;
  613. }
  614. if(myline >= 8) {
  615. P1OUT |= LED2;
  616. myline -= 8;
  617. }
  618. else{
  619. P1OUT &= ~LED2;
  620. }
  621. if(myline >= 4) {
  622. P2OUT |= LED3;
  623. myline -= 4;
  624. }
  625. else{
  626. P2OUT &= ~LED3;
  627. }
  628. if(myline >= 2) {
  629. P2OUT |= LED4;
  630. myline -= 2;
  631. }
  632. else{
  633. P2OUT &= ~LED4;
  634. }
  635. if(myline >= 1) {
  636. P2OUT |= LED5;
  637. myline -= 1;
  638. }
  639. else{
  640. P2OUT &= ~LED5;
  641. }
  642. // P1OUT = finalPort1;
  643. // P2OUT = finalPort2;
  644. }
  645.  
  646. int getNumArrayIndex(char c) {
  647. return c - 48;
  648. }
  649.  
  650. int squareRoot(int n) {
  651. int counter = 1;
  652. if(n == 0) {
  653. return 0;
  654. }
  655. while(1) {
  656. if((counter * counter) == n) {
  657. return counter;
  658. }
  659. else if(n < (counter * counter)) {
  660. int lowerTotal = (counter - 1) * (counter - 1);
  661. int higherTotal = counter * counter;
  662. if(n - lowerTotal < higherTotal - n) {
  663. return counter - 1;
  664. }
  665. return counter;
  666. }
  667. counter++;
  668. }
  669. }
  670.  
  671. void displayNum(char c) {
  672. int index = getNumArrayIndex(c);
  673. int i = 0;
  674. for(i = 0; i < 5; i++) {
  675. displayLine(numbers[index][i]);
  676. _delay_cycles(3000);
  677. }
  678. P1OUT &= ~(LED1 + LED2);
  679. P2OUT &= ~(LED3 + LED4 + LED5);
  680. }
  681.  
  682. //void displayChar(char* c) {
  683. // int i = 0;
  684. // for(i = 0; i < 10; i = i+2) {
  685. // displayLine(c[i]);
  686. // _delay_cycles(2000);
  687. // }
  688. // P1OUT = 0;
  689. // P2OUT &= ~(BIT0 + BIT1 + BIT2);
  690. //}
  691. //
  692. //void displayString(char* s) {
  693. // int i = 0;
  694. // for (i = 0; i<=strlen(s); i++) {
  695. // displayChar(s[i]);
  696. // _delay_cycles(2000);
  697. // }
  698. // _delay_cycles(4000);
  699. //}
  700.  
  701. void displayVal(int value) {
  702. int i = 0;
  703. char str[5];
  704. sprintf(str, "%d", value);
  705. for(i = 0; i < strlen(str); i++) {
  706. displayNum(str[i]);
  707. _delay_cycles(3000);
  708. }
  709. _delay_cycles(5000);
  710. //
  711. // for(i = 0; i < 3; i++) {
  712. // displayChar(bpm[i]);
  713. // _delay_cycles(3000);
  714. // }
  715.  
  716. if(mode == heartbeat) {
  717. for(i = 0; i < 7; i++) { //heart
  718. displayLine(heart[i]);
  719. _delay_cycles(3000);
  720. }
  721. }
  722. if(mode == steps) {
  723. for(i = 0; i < 9; i++){ //shoe
  724. displayLine(arrow[i]);
  725. _delay_cycles(5000);
  726. }
  727. }
  728. P1OUT &= ~(LED1 + LED2);
  729. P2OUT &= ~(LED3 + LED4 + LED5);
  730. _delay_cycles(30000);
  731. }
  732.  
  733.  
  734. int i = 0;
  735. int j = 0;
  736. int k = 0;
  737. int counter = 0;
  738. //codys
  739. //void displayNum(char c){
  740. // int index = getNumArrayIndex(c);
  741. // displayLine(numbers[index][j]);
  742. // j++;
  743. // if (j >= 5){
  744. // i++;
  745. // j = 0;
  746. // P1OUT &= ~(BIT4 + BIT5);
  747. // P2OUT &= ~(BIT0 + BIT1 + BIT2);
  748. // }
  749. //}
  750. //codys displayval
  751. //void displayVal (int value){
  752. // int tempCounter1 = 0;
  753. // int tempCounter2 = 0;
  754. //
  755. // counter ++;
  756. // char str[5];
  757. // sprintf(str, "%d", value);
  758. // if (i < strlen(str)){
  759. // if (((counter - 1) % 3) == 0){
  760. // displayNum(str[i]);
  761. // }
  762. // }
  763. // tempCounter1 = 1 + 5 + (strlen(str) * 18); // initial 1 + 5 between chars and heart + delay after final displayNum + time it takes to complete above code
  764. // if (counter >= tempCounter1){
  765. // if (mode == heartbeat){
  766. // if (k < 7){
  767. // if ((counter - tempCounter1) % 3 == 0){
  768. // displayLine(heart[k]);
  769. // k++;
  770. // tempCounter2 = counter;
  771. // }
  772. // }
  773. // else if (counter >= (tempCounter2 + 33)){
  774. // counter = 0;
  775. // tempCounter1 = 0;
  776. // tempCounter2 = 0;
  777. // i = 0;
  778. // j = 0;
  779. // k = 0;
  780. // P1OUT &= ~(BIT4 + BIT5);
  781. // P2OUT &= ~(BIT0 + BIT1 + BIT2);
  782. // }
  783. // else{
  784. // P1OUT &= ~(BIT4 + BIT5);
  785. // P2OUT &= ~(BIT0 + BIT1 + BIT2);
  786. // }
  787. // }
  788. // else if (mode == steps){
  789. // if (k < 9){
  790. // if ((counter - tempCounter1) % 5 == 0){
  791. // displayLine(heart[k]);
  792. // k++;
  793. // tempCounter2 = counter;
  794. // }
  795. // }
  796. // else if (counter >= (tempCounter2 + 35)){
  797. // counter = 0;
  798. // tempCounter1 = 0;
  799. // tempCounter2 = 0;
  800. // i = 0;
  801. // j = 0;
  802. // k = 0;
  803. // P1OUT &= ~(BIT4 + BIT5);
  804. // P2OUT &= ~(BIT0 + BIT1 + BIT2);
  805. // }
  806. // else{
  807. // P1OUT &= ~(BIT4 + BIT5);
  808. // P2OUT &= ~(BIT0 + BIT1 + BIT2);
  809. // }
  810. // }
  811. // }
  812. //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement