изменила форматирование. Добавила автовыбор ножек в зависимости от выбранной платы

This commit is contained in:
klassents committed 2025-03-27 13:55:05 +07:00
1 parent 78ef98a74d
commit f3df27f5fc
12 files changed
+261 -268

No files matched your search

@@ -14,38 +14,33 @@ void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
Serial.println("Hello");
while (!Serial) {
; // wait for serial port to connect. Needed for native USB, on LEONARDO, MICRO, YUN, and other 32u4 based boards.
}
// Semaphores are useful to stop a Task proceeding, where it should be paused to wait,
// because it is sharing a resource, such as the Serial port.
// Semaphores should only be used whilst the scheduler is running, but we can set it up here.
if ( xSerialSemaphore == NULL ) // Check to confirm that the Serial Semaphore has not already been created.
{
xSerialSemaphore = xSemaphoreCreateMutex(); // Create a mutex semaphore we will use to manage the Serial Port
xSerialSemaphore = xSemaphoreCreateMutex(); // Create a mutex semaphore we will use to manage the Serial Port
if ( ( xSerialSemaphore ) != NULL )
xSemaphoreGive( ( xSerialSemaphore ) ); // Make the Serial Port available for use, by "Giving" the Semaphore.
xSemaphoreGive( ( xSerialSemaphore ) ); // Make the Serial Port available for use, by "Giving" the Semaphore.
}
// Now set up two Tasks to run independently.
xTaskCreate(
TaskDigitalRead
, "DigitalRead" // A name just for humans
, 128 // This stack size can be checked & adjusted by reading the Stack Highwater
, NULL //Parameters for the task
, 2 // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest.
, NULL ); //Task Handle
TaskDigitalRead,
"DigitalRead", // A name just for humans
128, // This stack size can be checked & adjusted by reading the Stack Highwater
NULL, // Parameters for the task
2, // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest.
NULL); // Task Handle
xTaskCreate(
TaskAnalogRead
, "AnalogRead" // A name just for humans
, 128 // Stack size
, NULL //Parameters for the task
, 1 // Priority
, NULL ); //Task Handle
TaskAnalogRead,
"AnalogRead", // A name just for humans
128, // Stack size
NULL, // Parameters for the task
1, // Priority
NULL); // Task Handle
// Now the Task scheduler, which takes over control of scheduling individual Tasks, is automatically started.
}
@@ -53,7 +48,6 @@ void setup() {
void loop()
{
// Empty. Things are done in Tasks.
Serial.println("ping");
}
/*--------------------------------------------------*/
@@ -64,13 +58,17 @@ void TaskDigitalRead( void *pvParameters __attribute__((unused)) ) // This is a
{
/*
DigitalReadSerial
Reads a digital input on pin 2, prints the result to the serial monitor
Reads a digital input on pin pushButton, prints the result to the serial monitor
This example code is in the public domain.
*/
// digital pin 2 has a pushbutton attached to it. Give it a name:
uint8_t pushButton = 2;
#ifdef BTN_BUILTIN
uint8_t pushButton = BTN_BUILTIN;
#elif (defined(ARDUINO_ELSOMIK))
uint8_t pushButton = P0_0;
#else
uint8_t pushButton = 2;
#endif
// make the pushbutton's pin an input:
pinMode(pushButton, INPUT);
@@ -93,13 +91,12 @@ void TaskDigitalRead( void *pvParameters __attribute__((unused)) ) // This is a
xSemaphoreGive( xSerialSemaphore ); // Now free or "Give" the Serial Port for others.
}
vTaskDelay(1); // one tick delay (15ms) in between reads for stability
vTaskDelay(1); // one tick delay (10ms) in between reads for stability
}
}
void TaskAnalogRead( void *pvParameters __attribute__((unused)) ) // This is a Task.
{
for (;;)
{
// read the input on analog pin 0:
@@ -118,6 +115,6 @@ void TaskAnalogRead( void *pvParameters __attribute__((unused)) ) // This is a
xSemaphoreGive( xSerialSemaphore ); // Now free or "Give" the Serial Port for others.
}
vTaskDelay(1); // one tick delay (15ms) in between reads for stability
vTaskDelay(1); // one tick delay (10ms) in between reads for stability
}
}