Test session

Dependencies:   FatFileSystem MCP23017 WattBob_TextLCD mbed

Fork of Assignment_2_herpe by Xavier Herpe

Committer:
xouf2114
Date:
Tue Mar 14 14:46:43 2017 +0000
Revision:
4:48761259552a
Test of Assignment 2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
xouf2114 4:48761259552a 1 /**
xouf2114 4:48761259552a 2 * This task do a binary count on the 4 mbed LEDs
xouf2114 4:48761259552a 3 *
xouf2114 4:48761259552a 4 * Author: Jacob Baungard Hansen
xouf2114 4:48761259552a 5 */
xouf2114 4:48761259552a 6
xouf2114 4:48761259552a 7 #include "counting_task.h"
xouf2114 4:48761259552a 8
xouf2114 4:48761259552a 9 /**
xouf2114 4:48761259552a 10 *
xouf2114 4:48761259552a 11 * @param starting_offset when the task should but run first
xouf2114 4:48761259552a 12 * @param frequency_ms the frequency in ms of how often the task should run
xouf2114 4:48761259552a 13 */
xouf2114 4:48761259552a 14 CountingTask::CountingTask(int starting_offset, int frequency_ms)
xouf2114 4:48761259552a 15 : Task(starting_offset, frequency_ms) {
xouf2114 4:48761259552a 16
xouf2114 4:48761259552a 17 this->count = 0;
xouf2114 4:48761259552a 18
xouf2114 4:48761259552a 19 this->led1 = new DigitalOut(LED1);
xouf2114 4:48761259552a 20 this->led2 = new DigitalOut(LED2);
xouf2114 4:48761259552a 21 this->led3 = new DigitalOut(LED3);
xouf2114 4:48761259552a 22 this->led4 = new DigitalOut(LED4);
xouf2114 4:48761259552a 23
xouf2114 4:48761259552a 24
xouf2114 4:48761259552a 25 }
xouf2114 4:48761259552a 26
xouf2114 4:48761259552a 27 CountingTask::~CountingTask() {
xouf2114 4:48761259552a 28 delete this->led1;
xouf2114 4:48761259552a 29 delete this->led2;
xouf2114 4:48761259552a 30 delete this->led3;
xouf2114 4:48761259552a 31 delete this->led4;
xouf2114 4:48761259552a 32 }
xouf2114 4:48761259552a 33
xouf2114 4:48761259552a 34 /**
xouf2114 4:48761259552a 35 * The function that is run at the specified frequency.
xouf2114 4:48761259552a 36 */
xouf2114 4:48761259552a 37 void CountingTask::action() {
xouf2114 4:48761259552a 38
xouf2114 4:48761259552a 39 // simple way to get the bits
xouf2114 4:48761259552a 40 std::bitset<4> bits(this->count);
xouf2114 4:48761259552a 41
xouf2114 4:48761259552a 42 // set the result
xouf2114 4:48761259552a 43 this->led1->write(bits[3]);
xouf2114 4:48761259552a 44 this->led2->write(bits[2]);
xouf2114 4:48761259552a 45 this->led3->write(bits[1]);
xouf2114 4:48761259552a 46 this->led4->write(bits[0]);
xouf2114 4:48761259552a 47
xouf2114 4:48761259552a 48 // don't overflow
xouf2114 4:48761259552a 49 this->count = (this->count+1) % 16;
xouf2114 4:48761259552a 50
xouf2114 4:48761259552a 51 }