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.
Dependencies: C12832 mbed-rtos mbed
Fork of UTHM_TOT_MiniProject by
Revision 1:33b6bf21fbd4, committed 2016-08-17
- Comitter:
- nsuraya
- Date:
- Wed Aug 17 08:42:11 2016 +0000
- Parent:
- 0:004b3a49f410
- Commit message:
- tot_uthm
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed Aug 17 05:35:38 2016 +0000 +++ b/main.cpp Wed Aug 17 08:42:11 2016 +0000 @@ -1,103 +1,73 @@ #include "mbed.h" #include "rtos.h" #include "C12832.h" - -DigitalOut myled[]={LED1,LED2,LED3,LED4}; -AnalogIn pot(p20); -C12832 lcd(p5, p7, p6, p8, p11); -Serial pc(USBTX, USBRX); // tx, rx -PwmOut Speaker(p26); - -int frequency[ ] = {440,0,440,0,440,0,349,0,523,0,440,0,349,0,523,0,440,0, - 659,0,659,0,659,0,698,0,523,0,784,0,698,0,523,0,440,0}; -float beat[ ] = {1,0.4,1,0.4,1,0.4,0.8,0.1,0.4,0.1,1.2,0.2,0.8,0.1,0.4,0.1,1.2,1.6, - 1,0.4,1,0.4,1,0.4,0.8,0.1,0.4,0.1,1.2,0.2,0.8,0.1,0.4,0.1,1.2,0.8}; - - -typedef struct { - uint32_t raw_data; // ADC raw data - float voltage; // AD result of measured voltage -} message_t; - -MemoryPool<message_t, 16> mpool; -Queue<message_t, 16> queue; +AnalogIn port1(p19); +Serial pc(USBTX, USBRX); +C12832 lcd(p5, p7, p6, p8, p11); +AnalogIn port2(p20); +DigitalOut myled[] = {LED1,LED2,LED3,LED4}; + + + +int i, x = 1; -void Knight_Rider(void const *args) { - while(true){ - for(int i=0;i<4;i++) { - myled[i]=1; +void knight_rider(void const *args) { + while (true) { + + for(i=0; i<4; i++) { + myled [i]=1; Thread::wait(100); - myled[i]=0; - } - for(int i=2;i>0;i--) { - myled[i]=1; - Thread::wait(100); - myled[i]=0; + myled [i]=0; } - } -} -void ADC_Update(void const *args) { - pc.printf("\n\r|*----------------------------*|\n\r"); - pc.printf("|* Example ADC with Interrupt. |\n\r"); - pc.printf("|*----------------------------*|\n\r\n\r"); - while(1) { - //osSignalWait(0x01,osWaitForever); - message_t *message = mpool.alloc(); - message->raw_data = pot.read_u16(); - message->voltage = pot*3.3; - queue.put(message); // Place a value in the message queue - pc.printf("ADC Value is: %d \n\r\n\r", message->raw_data);// Display ADC value on UART - Thread::wait(1000); + for(i=2; i>0; i--) { + myled [i] = 1; + Thread::wait(100); + myled [i]=0; + + } + } } -void LCD_Display(void const *args) { - while (true) { - osEvent evt = queue.get(); - if (evt.status == osEventMessage) { - message_t *message = (message_t*)evt.value.p; - lcd.locate(0,11); - lcd.printf("Raw Data: %u" , message->raw_data); - lcd.locate(0,20); - lcd.printf("Voltage: %.2f volt" , message->voltage); - mpool.free(message); - } - Thread::wait(1000); +void ADC_pc(void const *args) { + + int j=0; + + printf("ADC with Interupt"); + + while(true) { // this is the third thread + + printf("Voltage : %3.3f V",port1.read()*3.3); + j++; + Thread::wait(100); + } } -void Music(void const *args) { - while(1) { - - for (uint8_t i=0; i<=35; i++) { - Speaker.period(1.0/frequency[i]); // 4 second period - Speaker=0.5; - Thread::wait(400*beat[i]); // hold for beat period - } +void ADC_lcd(void const *args) { + - /* - for (float i=2000.0; i<10000.0; i+=100) { - Speaker.period(1.0/i); - Speaker=0.5; - Thread::wait(100); - } - */ + int j=0; //local variable + lcd.cls(); //clear screen + lcd.locate(0,3); //point cursor + lcd.printf("Voltage Measurement"); + + while(true) { // this is the third thread + lcd.locate(0,20); + lcd.printf("Voltage : %3.3f V",port2.read()*3.3); + j++; + Thread::wait(1000); + } } - + int main() { - lcd.cls(); - lcd.locate(0,0); - lcd.printf("mBed-RTOS Mini Project"); + Thread tread1(knight_rider); + Thread tread2(ADC_pc); + Thread tread3(ADC_lcd); - //Thread thread1(Knight_Rider, (void *)"Th 1"), osPriorityNormal, (uint32_t) DEFAULT_STACK_SIZE, (unsigned char *)NULL); - Thread thread1(Knight_Rider); - Thread thread2(ADC_Update,(void *)"Th 2", osPriorityAboveNormal,DEFAULT_STACK_SIZE,NULL); - Thread thread3(LCD_Display); - Thread thread4(Music); - - while (true); + while (true) ; }