Skip to content

Commit

Permalink
[digital] added servo control
Browse files Browse the repository at this point in the history
  • Loading branch information
Dentrax committed Nov 11, 2018
1 parent 4bae64a commit fcf92f7
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions Chapter02-Digital/02-rtos-servo-control/02-rtos-servo-control.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// ====================================================
// 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>
#include <Servo.h>

#define PIN_SERVO_1 8
#define PIN_SERVO_2 9

Servo SERVO_1;
Servo SERVO_2;

void vTaskForward(void *pvParamethers);
void vTaskBackward(void *pvParamethers);

void setup() {
SERVO_1.attach(PIN_SERVO_1);
SERVO_2.attach(PIN_SERVO_2);

xTaskCreate(
vTaskForward,
(const portCHAR *) "vTaskForward",
100,
NULL,
1,
NULL
);

xTaskCreate(
vTaskBackward,
(const portCHAR *) "vTaskBackward",
100,
NULL,
2,
NULL
);

vTaskStartScheduler();
}

void loop() {
// Must be empty to run Tasks correctly
}

void vTaskForward(void *pvParameters){
(void) pvParameters;
const char *pcTaskName = "Task: ";

Serial.begin(9600);
Serial.println("Task[vTaskForward]::Initialized!");

for(;;){
Serial.println(pcTaskName);
SERVO_1.write(180);
SERVO_2.write(180);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}

void vTaskBackward(void *pvParameters){
(void) pvParameters;
const char *pcTaskName = "Task: ";

Serial.begin(9600);
Serial.println("Task[vTaskBackward]::Initialized!");

for(;;){
Serial.println(pcTaskName);
SERVO_1.write(90);
SERVO_2.write(90);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}

0 comments on commit fcf92f7

Please sign in to comment.