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

Committer:
rogerzuber
Date:
Thu Sep 23 18:04:03 2021 +0000
Revision:
0:680471563758
Multithreading Solution A13 - Roger Zuber (BZTF)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rogerzuber 0:680471563758 1 /*
rogerzuber 0:680471563758 2 * Copyright 2015 Benjamin R. Moeklegaard
rogerzuber 0:680471563758 3 *
rogerzuber 0:680471563758 4 * Licensed under the Apache License, Version 2.0 (the "License");
rogerzuber 0:680471563758 5 * you may not use this file except in compliance with the License.
rogerzuber 0:680471563758 6 * You may obtain a copy of the License at
rogerzuber 0:680471563758 7 *
rogerzuber 0:680471563758 8 * http://www.apache.org/licenses/LICENSE-2.0
rogerzuber 0:680471563758 9 *
rogerzuber 0:680471563758 10 * Unless required by applicable law or agreed to in writing, software
rogerzuber 0:680471563758 11 * distributed under the License is distributed on an "AS IS" BASIS,
rogerzuber 0:680471563758 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rogerzuber 0:680471563758 13 * See the License for the specific language governing permissions and
rogerzuber 0:680471563758 14 * limitations under the License.
rogerzuber 0:680471563758 15 */
rogerzuber 0:680471563758 16
rogerzuber 0:680471563758 17 #ifndef SHIFT_H
rogerzuber 0:680471563758 18 #define SHIFT_H
rogerzuber 0:680471563758 19
rogerzuber 0:680471563758 20 //Constant for managing n-numbers of registers, Function supported (writeByte, writeBit, writeBitAtPos)
rogerzuber 0:680471563758 21 #define REGISTER_CNT 2
rogerzuber 0:680471563758 22 /**
rogerzuber 0:680471563758 23 * This is a library for easy interfacing with the SN74HC595N 8-bit Shift Register.
rogerzuber 0:680471563758 24 * The library includes functions for writing bits, bytes and animation array to the register.
rogerzuber 0:680471563758 25 * The Functions are mainly based for writting 8-bits or one byte and can be moddified to work
rogerzuber 0:680471563758 26 * with multiple shift registers.
rogerzuber 0:680471563758 27 *@code
rogerzuber 0:680471563758 28 * #include "mbed.h"
rogerzuber 0:680471563758 29 * #include "ShiftOut.h"
rogerzuber 0:680471563758 30 * ShiftOut reg(PA_8, PA_9, PC_7, PB_6, D1);
rogerzuber 0:680471563758 31 *
rogerzuber 0:680471563758 32 * int main(){
rogerzuber 0:680471563758 33 * while(1){
rogerzuber 0:680471563758 34 * reg.writeBitAtPos(3, 1);
rogerzuber 0:680471563758 35 * wait(2);
rogerzuber 0:680471563758 36 * reg.writeByte(0x30);
rogerzuber 0:680471563758 37 * wait(2);
rogerzuber 0:680471563758 38 * }
rogerzuber 0:680471563758 39 * }@endcode
rogerzuber 0:680471563758 40 */
rogerzuber 0:680471563758 41
rogerzuber 0:680471563758 42 class ShiftOut
rogerzuber 0:680471563758 43 {
rogerzuber 0:680471563758 44 public:
rogerzuber 0:680471563758 45
rogerzuber 0:680471563758 46 /** Create a ShiftOut interface
rogerzuber 0:680471563758 47 *
rogerzuber 0:680471563758 48 * @param ser Serial data line
rogerzuber 0:680471563758 49 * @param srclk Data register clock
rogerzuber 0:680471563758 50 * @param rclk Output register clock
rogerzuber 0:680471563758 51 * @param oe Output enable (Active Low)
rogerzuber 0:680471563758 52 * @param reset Reset line for data register (Active Low)
rogerzuber 0:680471563758 53 * Writing Byte Example:
rogerzuber 0:680471563758 54 * @code
rogerzuber 0:680471563758 55 * #include "mbed.h"
rogerzuber 0:680471563758 56 * #include "ShiftOut.h"
rogerzuber 0:680471563758 57 *
rogerzuber 0:680471563758 58 * ShiftOut reg(PA_8, PA_9, PC_7, PB_6, D1);
rogerzuber 0:680471563758 59 * int main()
rogerzuber 0:680471563758 60 * {
rogerzuber 0:680471563758 61 * reg.writeByte(0x00); //Writes each bit to the SN74HC595N
rogerzuber 0:680471563758 62 * while(1) {
rogerzuber 0:680471563758 63 * wait_ms(300);
rogerzuber 0:680471563758 64 * }
rogerzuber 0:680471563758 65 * }
rogerzuber 0:680471563758 66 * @endcode
rogerzuber 0:680471563758 67 */
rogerzuber 0:680471563758 68
rogerzuber 0:680471563758 69
rogerzuber 0:680471563758 70 ShiftOut(PinName ser, PinName srclk, PinName rclk,
rogerzuber 0:680471563758 71 PinName oe, PinName reset);
rogerzuber 0:680471563758 72
rogerzuber 0:680471563758 73 /**
rogerzuber 0:680471563758 74 * Writes a byte to the shift register
rogerzuber 0:680471563758 75 * @param byte 0xXX or numbers from 0-255
rogerzuber 0:680471563758 76 */
rogerzuber 0:680471563758 77 void writeByte(unsigned char);
rogerzuber 0:680471563758 78
rogerzuber 0:680471563758 79 void write2Byte(unsigned int);
rogerzuber 0:680471563758 80
rogerzuber 0:680471563758 81
rogerzuber 0:680471563758 82 /**
rogerzuber 0:680471563758 83 * Writes a bit to the first output on the shift register
rogerzuber 0:680471563758 84 * @param bit 0 or 1
rogerzuber 0:680471563758 85 */
rogerzuber 0:680471563758 86
rogerzuber 0:680471563758 87 void writeBit(unsigned char);
rogerzuber 0:680471563758 88
rogerzuber 0:680471563758 89 /**
rogerzuber 0:680471563758 90 * Writes bits from an 2D array, with configurable delay
rogerzuber 0:680471563758 91 * @param int array, int lines, int delay_ms
rogerzuber 0:680471563758 92 * writes a 2D array with n-lines with a configurable delay in ms
rogerzuber 0:680471563758 93 * @code
rogerzuber 0:680471563758 94 * #include "mbed.h"
rogerzuber 0:680471563758 95 * #include "ShiftOut.h"
rogerzuber 0:680471563758 96 * ShiftOut reg(PA_8, PA_9, PC_7, PB_6, D1);
rogerzuber 0:680471563758 97 *
rogerzuber 0:680471563758 98 * int main(){
rogerzuber 0:680471563758 99 * int strobe[][8]= {{1,0,0,0,0,0,0,0},
rogerzuber 0:680471563758 100 * {0,1,0,0,0,0,0,0},
rogerzuber 0:680471563758 101 * {0,0,1,0,0,0,0,0},
rogerzuber 0:680471563758 102 * {0,0,0,1,0,0,0,0},
rogerzuber 0:680471563758 103 * {0,0,0,0,1,0,0,0},
rogerzuber 0:680471563758 104 * {0,0,0,0,0,1,0,0},
rogerzuber 0:680471563758 105 * {0,0,0,0,0,0,1,0},
rogerzuber 0:680471563758 106 * {0,0,0,0,0,0,0,1}};
rogerzuber 0:680471563758 107 * while(1){
rogerzuber 0:680471563758 108 * reg.animate(strobe, 8, 200);
rogerzuber 0:680471563758 109 * }
rogerzuber 0:680471563758 110 * }
rogerzuber 0:680471563758 111 * @endcode
rogerzuber 0:680471563758 112 */
rogerzuber 0:680471563758 113
rogerzuber 0:680471563758 114 void animate(int[][8], int, int);
rogerzuber 0:680471563758 115
rogerzuber 0:680471563758 116 /**
rogerzuber 0:680471563758 117 * Demonstrates two animation examples by using the animate function
rogerzuber 0:680471563758 118 */
rogerzuber 0:680471563758 119
rogerzuber 0:680471563758 120 void animationExample(void);
rogerzuber 0:680471563758 121
rogerzuber 0:680471563758 122 /**
rogerzuber 0:680471563758 123 * Writes the desired state to the output on the shift register
rogerzuber 0:680471563758 124 * @param char output, state
rogerzuber 0:680471563758 125 */
rogerzuber 0:680471563758 126
rogerzuber 0:680471563758 127 void writeBitAtPos(unsigned char, bool);
rogerzuber 0:680471563758 128
rogerzuber 0:680471563758 129 /**
rogerzuber 0:680471563758 130 * Writes the corresponding array item to the output on the shift register
rogerzuber 0:680471563758 131 * @param char array writes to the output from a state array
rogerzuber 0:680471563758 132 */
rogerzuber 0:680471563758 133
rogerzuber 0:680471563758 134 void writeArray(char[8]);
rogerzuber 0:680471563758 135
rogerzuber 0:680471563758 136 protected:
rogerzuber 0:680471563758 137 void updateRegister(void);
rogerzuber 0:680471563758 138 void updateOutput(void);
rogerzuber 0:680471563758 139 void clearStateArray(void);
rogerzuber 0:680471563758 140 DigitalOut DSERIAL, LATCH, RCLK, SRCLK, RESET;
rogerzuber 0:680471563758 141
rogerzuber 0:680471563758 142 };
rogerzuber 0:680471563758 143
rogerzuber 0:680471563758 144 #endif