Skip to content

Commit

Permalink
[analog] added analogread example
Browse files Browse the repository at this point in the history
  • Loading branch information
Dentrax committed Nov 11, 2018
1 parent 3757b7a commit 2dda09a
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions Chapter03-Analog/01-rtos-analog-read/01-rtos-analog-read.ino
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
}

0 comments on commit 2dda09a

Please sign in to comment.