Multithreading Solution for A13 Temperatur, Servo, Display Roger Zuber, BZTF

main.cpp

Committer:
rogerzuber
Date:
2021-09-23
Revision:
0:680471563758
Child:
1:12451c43fd61

File content as of revision 0:680471563758:

/* mbed Microcontroller Library
 * Copyright (c) 2019 ARM Limited
 * SPDX-License-Identifier: Apache-2.0
 */

#include "mbed.h"
#include "platform/mbed_thread.h"
#include "ShiftOut.h"

// Blinking rate in milliseconds
#define BLINKING_RATE_MS 500

ShiftOut Seg7(D8, D7, D4, D13, D12);

const char SEGMENT_MAP[] = {0x03,0x9F,0x25,0x0D,0x99,0x49,0x41,0x1F,0x01,0x09};
const char SEGMENT_SELECT[] = {0x8F,0x4F,0x2F,0x1F};

Thread Thread1;

int counter = 1234;

void Anzeige_Thread(void)
{
    while (1)
    {
        for (int delay = 0 ; delay < 10 ; delay++) {
            Seg7.write2Byte(SEGMENT_MAP[counter/1000] + (SEGMENT_SELECT[0]<<8));
            Seg7.write2Byte(SEGMENT_MAP[counter%1000/100] + (SEGMENT_SELECT[1]<<8));
            Seg7.write2Byte(SEGMENT_MAP[counter%100/10] + (SEGMENT_SELECT[2]<<8));
            Seg7.write2Byte(SEGMENT_MAP[counter%10] + (SEGMENT_SELECT[3]<<8));
        }
        ThisThread::sleep_for(1);
    }
}

int main()
{
    // Initialise the digital pin LED1 as an output
    DigitalOut led(LED1);
    
    Thread1.start(Anzeige_Thread);             // Thread starten

    while (true) {
        led = !led;
        counter++;
        thread_sleep_for(BLINKING_RATE_MS);
    }
}