-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
Chapter03-Analog/01-rtos-analog-read/01-rtos-analog-read.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// ==================================================== | ||
// ArduRTOS Copyright(C) 2018 Furkan Türkal | ||
// This program comes with ABSOLUTELY NO WARRANTY; This is free software, | ||
// and you are welcome to redistribute it under certain conditions; See | ||
// file LICENSE, which is part of this source code package, for details. | ||
// ==================================================== | ||
|
||
#include <Arduino_FreeRTOS.h> | ||
|
||
#define PIN_SENSOR A0 | ||
#define PIN_BUTTON 2 | ||
|
||
void vTask(void *pvParamethers); | ||
|
||
void setup() { | ||
pinMode(PIN_SENSOR, INPUT); | ||
pinMode(PIN_BUTTON, INPUT); | ||
|
||
xTaskCreate( | ||
vTask, | ||
(const portCHAR *) "Task", | ||
100, | ||
NULL, | ||
1, | ||
NULL | ||
); | ||
|
||
vTaskStartScheduler(); | ||
} | ||
|
||
void loop() { | ||
// Must be empty to run Tasks correctly | ||
} | ||
|
||
void vTask(void *pvParameters){ | ||
(void) pvParameters; | ||
const char *pcTaskName = "Task: "; | ||
|
||
Serial.begin(9600); | ||
Serial.println("Task[vTask]::Initialized!"); | ||
|
||
int16_t sStateButton = LOW; | ||
int16_t sValueSensor = 0; | ||
|
||
for(;;){ | ||
Serial.println(pcTaskName); | ||
|
||
sStateButton = digitalRead(PIN_BUTTON); | ||
sValueSensor = analogRead(PIN_SENSOR); | ||
|
||
if (sStateButton == HIGH) { | ||
Serial.print("Analog Read:"); | ||
Serial.println(sValueSensor); | ||
} | ||
|
||
vTaskDelay(10 / portTICK_PERIOD_MS); | ||
} | ||
vTaskDelete(NULL); | ||
//Delete task if for-loop breaked | ||
} |