initial
This commit is contained in:
61
src/main.cpp
Normal file
61
src/main.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
#include <Arduino.h>
|
||||
#include <STM32FreeRTOS.h>
|
||||
#include <pivector.h>
|
||||
|
||||
|
||||
//global vars
|
||||
volatile int val = 0;
|
||||
|
||||
|
||||
//functions
|
||||
void TaskBlink(void *pvParameters);
|
||||
void keyPressed();
|
||||
|
||||
|
||||
// initialization
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
while (!Serial);
|
||||
pinMode(A0, INPUT_PULLUP);
|
||||
attachInterrupt(A0, keyPressed, FALLING);
|
||||
xTaskCreate(
|
||||
TaskBlink,
|
||||
(const portCHAR *)"Blink", // A name just for humans
|
||||
128, // This stack size can be checked & adjusted by reading the Stack Highwater
|
||||
NULL,
|
||||
2, // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest.
|
||||
NULL
|
||||
);
|
||||
Serial.println("Starting");
|
||||
Serial.flush();
|
||||
vTaskStartScheduler(); // start FreeRTOS, function don't exit
|
||||
Serial.println("Start FreeRTOS failed! Insufficient RAM");
|
||||
while(1); // panic
|
||||
}
|
||||
|
||||
void loop(){} // unused
|
||||
|
||||
|
||||
// This is a task.
|
||||
void TaskBlink(void *) {
|
||||
int d = 100;
|
||||
pinMode(PC13, OUTPUT);
|
||||
PIVector<float> vec;
|
||||
vec.resize(10, [](size_t i){return i*2;});
|
||||
while (1) {
|
||||
Serial.println("TaskBlink");
|
||||
for (float f : vec) Serial.println(f);
|
||||
if (val > 0) d = 300;
|
||||
else d = 100;
|
||||
digitalWrite(PC13, HIGH);
|
||||
vTaskDelay(d / portTICK_PERIOD_MS);
|
||||
digitalWrite(PC13, LOW);
|
||||
vTaskDelay(d / portTICK_PERIOD_MS);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// key interrupt
|
||||
void keyPressed() {
|
||||
val = 1 - val;
|
||||
}
|
||||
Reference in New Issue
Block a user