Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
@MicroBeaut
MicroBeaut
Follow
View MicroBeaut's full-sized avatar

MicroBeaut MicroBeaut

Practice Makes Perfect

Highlights

  • Pro

Block or report MicroBeaut

Block user

Prevent this user from interacting with your repositories and sending you notifications. Learn more aboutblocking users.

You must be logged in to block users.

Maximum 250 characters. Please don't include any personal information such as legal names or email addresses. Markdown supported. This note will be visible to only you.
Report abuse

Contact GitHub support about this user’s behavior. Learn more aboutreporting abuse.

Report abuse
MicroBeaut/README.md

Applied PLC's Technique, Concept, and Function to Microcontroller is named "Applied Microcontroller Programming" and shared my Libraries "MicroBeaut" with you.

1. Timer

  • Debounce
  • TimerOn (Timer On)
  • TimerOff (Timer Off)
  • TimePulse (Time Pulse)
  • Blink
  • Trigger

2. Bistable

  • SR (Set Dominant)
  • RS (Reset Dominant)
  • Toggle

3. Edge

  • Rising (Rising Edge)
  • Falling (Falling Edge)

4. Schedule

  • TimeSchedule (Schedule execution at specified time intervals)
  • ScanSchedule (Schedules execution after a certain number of scans)

All of them are generic functions that can help you do Microcontroller Programming efficiently.

Timer Group used "micros()" of Arduino function for calculating elapsed time. As I call " Continuous" tasks, you can use them for multitasking programs. Still, don't forget a delay() function; you may sometimes require to use it as an initiative of some process.

Bistable and Edge Group are essential functions to detect or turn bit On / Off. Without thinking about managing their program, you can use these libraries in your program.

The Schedule is a choice for your to execute your subroutine by Time or Scans.

I hope you will enjoy Microcontroller Programming and hope these libraries may help you manage your program easily.


Timer

Debounce

The debounce function delays TimeDebounce from the rising edge and falling edge of input to the output's rising edge and falling edge.

The rising edge of the input starts the timer. While the input is TRUE, after a delay of duration TimeDebounce, the timer changes the output to TRUE.The falling edge of the input starts the timer. While the input is FALSE, after a delay of duration TimeDebounce, the timer changes the output to FALSE.

Syntax:

Declaration

MicroBeaut_DebouncefunctionVariable;

Function Use

functionVariable.setTimeDebounce(uint16TimeDebounceInMillisec);boolReturnValue=functionVariable.readInput(boolVariableInput);

Getting other values from Function

`Output State

`

boolReturnOutput=functionVariable.readStatus();
Time Debounce Setting
uint16ReturnTimeInMillisec=functionVariable.getTimeDebounce();
Elapsed Time
uint16ReturnTimeInMillisec=functionVariable.getElapsedTime();

Example:

#include"MicroBeaut.h"#defineinputPin 8  // Define Input PinMicroBeaut_DebouncedebFunction;// Debounce VariableboolinputState;// Input StateboolprevInput;// Previous Input StatebooloutputState;// Output Stateconstuint16_tmsTimeDebounce=10;// Time Debounce = 10 millisecondsvoidsetup() {pinMode(inputPin,INPUT);// Set Pin as an Input ModepinMode(LED_BUILTIN,OUTPUT);// Set Pin as an Output ModedebFunction.setTimeDebounce(msTimeDebounce);// Set Time Debounce}voidloop() {prevInput=inputState;// Previous Input = Current InputinputState=debFunction.readInput(digitalRead(inputPin));// Read Input and DebounceoutputState ^= (inputState& !prevInput);// Toggle OutputdigitalWrite(LED_BUILTIN,outputState);// Write Output}

TimerOn (Timer On)

The timer on function delays TimeDelay from the input's rising edge to the output's rising edge.

The rising edge of the input starts the timer. While the input is TRUE, after a delay of duration TimeDelay, the timer changes the output to TRUE. If the input changes to FALSE at any time, the timer resets, reversing the result to FALSE and elapsed time to zero.

Syntax:

Declaration

MicroBeaut_TimeOnfunctionVariable;

Function Use

functionVariable.setTimeDelay(msTimeDelay);boolReturnValue=functionVariable.readInput(boolVariableInput);

Getting other values from Function

`Output State

`

boolReturnOutput=functionVariable.readStatus();
Time Delay Setting
uint16ReturnTimeInMillisec=functionVariable.getTimeDelay();
Elapsed Time
uint16ReturnTimeInMillisec=functionVariable.getElapsedTime();

Example:

#include"MicroBeaut.h"#defineinputPin 8  // Define Input PinMicroBeaut_TimerOntonFunction;// Timer On VariableboolinputState;// Input StatebooloutputState;// Output Stateconstuint16_tmsTimeDelay=1000;// Time Delay = 1 Secondvoidsetup() {pinMode(inputPin,INPUT);// Set Pin as an Input ModepinMode(LED_BUILTIN,OUTPUT);// Set Pin as an Output ModetonFunction.setTimeDelay(msTimeDelay);// Set Time Delay}voidloop() {inputState=digitalRead(inputPin);// Read InputoutputState=tonFunction.readInput(inputState);// Timer On Function with InputdigitalWrite(LED_BUILTIN,outputState);// Write Output}

TimerOff (Timer Off)

The timer off function delays TimeDelay from the input's falling edge to the output's falling edge.

The falling edge of the input starts the timer. While the input is FALSE, after a delay of duration TimeDelay, the timer changes the output to FALSE. If the input changes to TRUE at any time, the timer resets, reversing the result to TRUE and elapsed time to zero.

Syntax:

Declaration

MicroBeaut_TimeOnfunctionVariable;

Function Use

functionVariable.setTimeDelay(msTimeDelay);boolReturnValue=functionVariable.readInput(boolVariableInput);

Getting other values from Function

`Output State

`

boolReturnOutput=functionVariable.readStatus();
Time Delay Setting
uint16ReturnTimeInMillisec=functionVariable.getTimeDelay();
Elapsed Time
uint16ReturnTimeInMillisec=functionVariable.getElapsedTime();

Example:

#include"MicroBeaut.h"#defineinputPin 8  // Define Input PinMicroBeaut_TimerOfftofFunction;// Timer Off VariableboolinputState;// Input StatebooloutputState;// Output Stateconstuint16_tmsTimeDelay=1000;// Time Delay = 1 Secondvoidsetup() {pinMode(inputPin,INPUT_PULLUP);// Set Pin as an Input ModepinMode(LED_BUILTIN,OUTPUT);// Set Pin as an Output ModetofFunction.setTimeDelay(msTimeDelay);// Set Time Delay}voidloop() {inputState=digitalRead(inputPin);// Read InputoutputState=tofFunction.readInput(inputState);// Timer Off Function with InputdigitalWrite(LED_BUILTIN,outputState);// Write Output}

TimePulse (Time Pulse)

The time pulse function generates a pulse of duration TimeDelay starting on the rising edge of the input.

The rising edge of the input starts the timer, setting output to TRUE. While the output is TRUE, the timer ignores the input.

Syntax:

Declaration

MicroBeaut_TimePulsefunctionVariable;

Function Use

functionVariable.setTimeDelay(msTimeDelay);boolReturnValue=functionVariable.readInput(boolVariableInput);

Getting other values from Function

`Output State

`

boolReturnOutput=functionVariable.readStatus();
Time Pulse Setting
uint16ReturnTimeInMillisec=functionVariable.getTimeDelay();
Elapsed Time
uint16ReturnTimeInMillisec=functionVariable.getElapsedTime();

Example:

#include"MicroBeaut.h"#defineinputPin 8  // Define Input PinMicroBeaut_TimePulsetpFunction;// Time Pulse VariableboolinputState;// Input StatebooloutputState;// Output Stateconstuint16_tmsTimeDelay=1000;// Time Pulse = 1 Secondvoidsetup() {pinMode(inputPin,INPUT);// Set Pin as an Input ModepinMode(LED_BUILTIN,OUTPUT);// Set Pin as an Output ModetpFunction.setTimeDelay(msTimeDelay);// Set Time Pulse}voidloop() {inputState=digitalRead(inputPin);// Read InputoutputState=tpFunction.readInput(inputState);// Time Pulse Function with InputdigitalWrite(LED_BUILTIN,outputState);// Write Output}

Blink

The input enables blinking. The blink function generates a pulse output that is supposed to repeatedly turn the result on and off. The reset input resets the output to FALSE and initiates the pulse-off period. TimeDelayOn specifies how long the pulse is on; TimeDelayOff specifies how long the pulse is off.

Syntax:

Declaration

MicroBeaut_BlinkfunctionVariable;

Function Use

functionVariable.setTimeDelay(msTimeDelayOff,msTimeDelayOn);boolReturnValue=functionVariable.readInput(boolVariableInput= true);

Getting other values from Function

`Output State

`

boolReturnOutput=functionVariable.readStatus();
Time Blink Setting
uint16ReturnTimeInMillisec=functionVariable.getTimeDelay();
Elapsed Time
uint16ReturnTimeInMillisec=functionVariable.getElapsedTime();

Example:

#include"MicroBeaut.h"#defineinputPin 8  // Define Input PinMicroBeaut_BlinkblinkFunction;// Blink VariableboolenableState;// Enable State (0 = Disable, 1=Enable)booloutputState;// Output Stateconstuint16_tmsTimeDelayOff=250;// OFF Delay = 0.25 secondconstuint16_tmsTimeDelayOn=500;// ON Delay = 0.5 secondvoidsetup() {pinMode(inputPin,INPUT_PULLUP);// Set Pin as an Input ModepinMode(LED_BUILTIN,OUTPUT);// Set Pin as an Output ModeblinkFunction.setTimeDelay(msTimeDelayOff,msTimeDelayOn);// Set Blink}voidloop() {enableState=digitalRead(inputPin);// Read Input (0 = Disable, 1 = Enable)outputState=blinkFunction.readInput(enableState);// Blink Function with Enable InputdigitalWrite(LED_BUILTIN,outputState);// Write Output}

Trigger

The trigger function sets the output only one scan.

The rising edge of the input starts the timer. While the input is TRUE, after a delay of duration TimeDelay, the timer changes the output to TRUE and restarts the timer. If the input changes to FASE at any time, the timer holds the last value.

The reset input resets the output to FALSE and resets the timer.

Syntax:

Declaration

MicroBeaut_TriggerfunctionVariable;

Function Use

functionVariable.setTimeDelay(msTimeDelay);boolReturnValue=functionVariable.readInput(boolVariableInput= true,boolVariableReset= false);

Getting other values from Function

`Output State

`

boolReturnOutput=functionVariable.readStatus();
Time Delay Setting
uint16ReturnTimeInMillisec=functionVariable.getTimeDelay();
Elapsed Time
uint16ReturnTimeInMillisec=functionVariable.getElapsedTime();

Example:

#include"MicroBeaut.h"#defineinputPin 8  // Define Input Pin#defineresetPin 9  // Define Input PinMicroBeaut_TriggertrigFunction;// Trigger VariableboolinputState;// Input StateboolresetState;// Input StatebooloutputState;// Output StatebooltrigState;// Trigger Stateconstuint16_tmsTimeDelay=1000;// Trigger Delay = 1 Secondvoidsetup() {Serial.begin(115200);pinMode(inputPin,INPUT_PULLUP);// Set Pin as an Input ModepinMode(resetPin,INPUT);// Set Pin as an Input ModepinMode(LED_BUILTIN,OUTPUT);// Set Pin as an Output ModetrigFunction.setTimeDelay(msTimeDelay);// Set Trigger Delay}voidloop() {inputState=digitalRead(inputPin);// Read InputresetState=digitalRead(resetPin);// Read InputoutputState=trigFunction.readInput(inputState,resetState);// Trigger Function with InputdigitalWrite(LED_BUILTIN,outputState);// Write Outputif(trigFunction.readStatus()) {Serial.println("Applying MicroBeaut to your program will make it easier to manage your Multitasking Programming.");}}

Bistable

SR (Set Dominant)

The RS function block is a latch with the reset input dominant over the set input. The reset input resets output to false. The set input sets the output to TRUE if reset is FALSE. If reset is FALSE and set is FALSE, the output does not change.

Syntax:

Declaration

MicroBeaut_SRfunctionVariable;

Function Use

boolReturnValue=functionVariable.readInput(boolVariableSet,boolVariableReset);

Getting another value from Function

`Output State

`

boolReturnOutput=functionVariable.readStatus();

Example:

#include"MicroBeaut.h"#definesetPin 8    // Define Input Pin#defineresetPin 9  // Define Input PinMicroBeaut_SRsrFunction;// SR VariableboolsetState;// Input StateboolresetState;// Input StatebooloutputState;// Output Statevoidsetup() {pinMode(setPin,INPUT_PULLUP);// Set Pin as an Input ModepinMode(resetPin,INPUT);// Set Pin as an Input ModepinMode(LED_BUILTIN,OUTPUT);// Set Pin as an Output Mode}voidloop() {setState=digitalRead(setPin);// Read InputresetState=digitalRead(resetPin);// Read InputoutputState=srFunction.readInput(setState,resetState);// SR Function with Set and ResetdigitalWrite(LED_BUILTIN,outputState);// Write Output}

RS (Reset Dominant)

The RS function is a latch with the reset input dominant over the set input. Thereset input resets output to FALSE. The set input sets output to TRUE if reset is false. If reset is FALSE andS is FASE, then Q1 does not change.

Syntax:

Declaration

MicroBeaut_RSfunctionVariable;

Function Use

boolReturnValue=functionVariable.readInput(boolVariableSet,boolVariableReset);

Getting another value from Function

`Output State

`

boolReturnOutput=functionVariable.readStatus();

Example:

#include"MicroBeaut.h"#definesetPin 8    // Define Input Pin#defineresetPin 9  // Define Input PinMicroBeaut_RSrsFunction;// RS VariableboolsetState;// Input StateboolresetState;// Input StatebooloutputState;// Output Statevoidsetup() {pinMode(setPin,INPUT_PULLUP);// Set Pin as an Input ModepinMode(resetPin,INPUT);// Set Pin as an Input ModepinMode(LED_BUILTIN,OUTPUT);// Set Pin as an Output Mode}voidloop() {setState=digitalRead(setPin);// Read InputresetState=digitalRead(resetPin);// Read InputoutputState=rsFunction.readInput(setState,resetState);// RS Function with Set and ResetdigitalWrite(LED_BUILTIN,outputState);// Write Output}

Toggle

The rising edge of input "Input" toggles readStatus. Input "Reset" resets readStatus (to FALSE).

Syntax:

Declaration

MicroBeaut_TogglefunctionVariable;

Function Use

boolReturnValue=functionVariable.readInput(boolVariableInput,boolVariableReset= false);

Getting another value from Function

`Output State

`

boolReturnOutput=functionVariable.readStatus();

Example:

#include"MicroBeaut.h"#defineinputPin 8  // Define Input Pin#defineresetPin 9  // Define Input PinMicroBeaut_ToggletogFunction;// RS VariableboolinputState;// Input StateboolresetState;// Input StatebooloutputState;// Output Statevoidsetup() {pinMode(inputPin,INPUT);// Set Pin as an Input ModepinMode(resetPin,INPUT);// Set Pin as an Input ModepinMode(LED_BUILTIN,OUTPUT);// Set Pin as an Output Mode}voidloop() {inputState=digitalRead(inputPin);// Read InputresetState=digitalRead(resetPin);// Read InputoutputState=togFunction.readInput(inputState,resetState);// Toggle Function with Input and ResetdigitalWrite(LED_BUILTIN,outputState);// Write Output}

Edge

Rising (Rising Edge)

Set readStatus on the rising edge of Input.

Syntax:

Declaration

MicroBeaut_RisingfunctionVariable;

Function Use

boolReturnValue=functionVariable.readInput(boolVariableInput);

Getting another value from Function

`Output State

`

boolReturnOutput=functionVariable.readStatus();

Example:

#include"MicroBeaut.h"#defineinputPin 8  // Define Input PinMicroBeaut_RisingreFunction;// Rising Edge VariableboolinputState;// Input StateboolprevInput;// Previous Input StatebooloutputState;// Output Statevoidsetup() {pinMode(inputPin,INPUT);// Set Pin as an Input ModepinMode(LED_BUILTIN,OUTPUT);// Set Pin as an Output Mode}voidloop() {prevInput=inputState;// Previous Input = Current InputinputState=reFunction.readInput(digitalRead(inputPin));// Read Input and Rising Edge DetectoroutputState ^= (inputState& !prevInput);// Toggle OutputdigitalWrite(LED_BUILTIN,outputState);// Write Output}

Falling (Falling Edge)

Set readStatus on the falling edge of Input.

Syntax:

Declaration

MicroBeaut_FallingfunctionVariable;

Function Use

boolReturnValue=functionVariable.readInput(boolVariableInput);

Getting another value from Function

`Output State

`

boolReturnOutput=functionVariable.readStatus();

Example:

#include"MicroBeaut.h"#defineinputPin 8  // Define Input PinMicroBeaut_FallingfeFunction;// Falling Edge VariableboolinputState;// Input StateboolprevInput;// Previous Input StatebooloutputState;// Output Statevoidsetup() {pinMode(inputPin,INPUT);// Set Pin as an Input ModepinMode(LED_BUILTIN,OUTPUT);// Set Pin as an Output Mode}voidloop() {prevInput=inputState;// Previous Input = Current InputinputState=feFunction.readInput(digitalRead(inputPin));// Read Input and Falling Edge DetectoroutputState ^= (inputState& !prevInput);// Toggle OutputdigitalWrite(LED_BUILTIN,outputState);// Write Output}

Schedule

TimeSchedule (Schedule execution at specified time intervals)

The TimeSchedule function is used to schedule a selected subroutine's execution after the specified period of time has passed and the output is TRUE for one scan. Otherwise, the output is FALSE. Input enables the function.

Syntax:

Declaration

MicroBeaut_TimeSchedulefunctionVariable;

Function Use

functionVariable.setTimeSchedule(uint16TimeScheduleInSecond,CallbackFunction);boolReturnValue=functionVariable.readInput(boolVariableEnable= true);

Example:

#include"MicroBeaut.h"#defineinputPin 8  // Define Input PinMicroBeaut_TimeScheduletsFunction;// Time Schedule VariableboolenableState;// Input StatebooloutputState;// Output Stateconstuint16_ttimeSchedule=1000;// Time Schedule = 1 Secondvoidsetup() {pinMode(inputPin,INPUT_PULLUP);// Set Pin as an Input ModepinMode(LED_BUILTIN,OUTPUT);// Set Pin as an Output ModetsFunction.setTimeSchedule(timeSchedule,ToggleStateRoutine);// Set Time Schedule and Callback Function}voidloop() {enableState=digitalRead(inputPin);// Read InputtsFunction.readInput(enableState);// Time Schedule Function with EnabledigitalWrite(LED_BUILTIN,outputState);// Write Output}voidToggleStateRoutine() {outputState= !outputState;}

ScanSchedule (Schedules execution after a certain number of scans)

The ScanSchedule function is used to schedule a selected subroutine's execution after a specified number of scans occur. Input enables the function. readStatus is TRUE after the specified number of scans occur and holds TRUE for one scan.

Syntax:

Declaration

MicroBeaut_ScanSchedulefunctionVariable;

Function Use

functionVariable.setScanSchedule(uIntNumberOfScan,CallbackFunction);boolReturnValue=functionVariable.readInput(boolVariableEnable);

Getting other values from Function

`Output State

`

boolReturnOutput=functionVariable.readStatus();
Actual Time
uint16ReturnActualTimeInMillisec=functionVariable.Actual();

Example:

#include"MicroBeaut.h"#defineinputPin 8  // Define Input PinMicroBeaut_ScanSchedulessFunction;// Scan Schedule VariableboolenableState;// Enable StatebooloutputState;// Output Stateconstunsigned longnumberOfScan=17450;// Number of scansvoidsetup() {pinMode(inputPin,INPUT_PULLUP);// Set Pin as an Input ModepinMode(LED_BUILTIN,OUTPUT);// Set Pin as an Output ModessFunction.setScanSchedule(numberOfScan,ToggleStateRoutine);// Set Scan Schedule and Callback Function}voidloop() {enableState=digitalRead(inputPin);// Read InputssFunction.readInput(enableState);// Scan Schedule Function with EnabledigitalWrite(LED_BUILTIN,outputState);// Write Output}voidToggleStateRoutine() {outputState= !outputState;}

Reference

Triconex TriStation™ 1131 Developer’s Workbench Libraries

PinnedLoading

  1. MicroBeaut-VBA-SnippetsMicroBeaut-VBA-SnippetsPublic

    MicroBeaut Visual Basic for Applications (VBA) Snippets

    2

  2. MicroBeautMicroBeautPublic

    Applied Microcontroller Programming (AuCP)

    C++


[8]ページ先頭

©2009-2025 Movatter.jp