Test session
Dependencies: FatFileSystem MCP23017 WattBob_TextLCD mbed
Fork of Assignment_2_herpe by
counting_task.cpp
00001 /** 00002 * This task do a binary count on the 4 mbed LEDs 00003 * 00004 * Author: Jacob Baungard Hansen 00005 */ 00006 00007 #include "counting_task.h" 00008 00009 /** 00010 * 00011 * @param starting_offset when the task should but run first 00012 * @param frequency_ms the frequency in ms of how often the task should run 00013 */ 00014 CountingTask::CountingTask(int starting_offset, int frequency_ms) 00015 : Task(starting_offset, frequency_ms) { 00016 00017 this->count = 0; 00018 00019 this->led1 = new DigitalOut(LED1); 00020 this->led2 = new DigitalOut(LED2); 00021 this->led3 = new DigitalOut(LED3); 00022 this->led4 = new DigitalOut(LED4); 00023 00024 00025 } 00026 00027 CountingTask::~CountingTask() { 00028 delete this->led1; 00029 delete this->led2; 00030 delete this->led3; 00031 delete this->led4; 00032 } 00033 00034 /** 00035 * The function that is run at the specified frequency. 00036 */ 00037 void CountingTask::action() { 00038 00039 // simple way to get the bits 00040 std::bitset<4> bits(this->count); 00041 00042 // set the result 00043 this->led1->write(bits[3]); 00044 this->led2->write(bits[2]); 00045 this->led3->write(bits[1]); 00046 this->led4->write(bits[0]); 00047 00048 // don't overflow 00049 this->count = (this->count+1) % 16; 00050 00051 }
Generated on Thu Jul 14 2022 10:33:15 by
1.7.2
