Skip to content

Commit

Permalink
Version 1.4 add more examples
Browse files Browse the repository at this point in the history
  • Loading branch information
BlynkGO committed Sep 23, 2022
1 parent cca70fe commit d9012c7
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <TridentTD_EasyFreeRTOS32.h>

TridentOS task1, task2, task3, task4, task5; // ประกาศตัวแปร task
EasyFreeRTOS32 task1, task2, task3, task4, task5; // ประกาศตัวแปร task
void task1_func(void*), task2_func(void*), // ฟังกชั่นที่ task จะเรียกทำงาน
task3_func(void*), task4_func(void*), task5_func(void*);

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
63 changes: 63 additions & 0 deletions example/04.task_with_del/04.task_with_del.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include <TridentTD_EasyFreeRTOS32.h>
#include <WiFi.h>
#include <DFRobot_SHT20.h>
#include <Wire.h>

#define SSID "----------"
#define PASSWORD "----------"
#define SHT20_I2C_SDA 22
#define SHT20_I2C_SCL 25


// ประกาศ ตัวแปร task และ function สำหรับ task
EasyFreeRTOS32 WiFi_task, SHT20_task;


void setup(){ // setup() หลักตัวพิมพ์เล็ก
Serial.begin(115200); Serial.println();

WiFi_task.start(CORE0, 4096, [](void *param){
VOID SETUP(){
Serial.println("[WiFi] begin ...");
WiFi.begin(SSID, PASSWORD);
}
VOID LOOP(){
if( !WiFi.isConnected() ) {
while(!WiFi.isConnected() ) DELAY(400);
Serial.print("[WiFi] WiFi Connected, IP : ");
Serial.println(WiFi.localIP());
}
DELAY(10000);
}
});

SHT20_task.start(CORE1, [](void*param){
DFRobot_SHT20 sht20(&Wire1, SHT20_I2C_ADDR);
bool sht20_is_inited= false;
VOID SETUP(){
Serial.println("[SHT20] initing..");
Wire1.begin(SHT20_I2C_SDA, SHT20_I2C_SCL);
Wire1.beginTransmission(SHT20_I2C_ADDR);
sht20_is_inited = (0== Wire1.endTransmission());
if(sht20_is_inited ) {
Serial.println("[SHT20] init OK"); //SHT20_I2C_ADDR
}else{
Serial.println("[SHT20] init failed");
SHT20_task.del(); // ทำลาย SHT20_task ทิ้งไปไม่ต้องทำงานอีก
}
}
VOID LOOP(){
DELAY(1000);
if(sht20_is_inited ) {
float sht_temp = sht20.readTemperature();
float sht_hum = sht20.readHumidity();

Serial.printf("[SHT20] Tempperature : %.2f °C\n", sht_temp);
Serial.printf("[SHT20] Humidity : %.2f %%\n", sht_hum);
}
}
});
}

void loop(){ DELAY(1); } // loop() หลักตัวพิมพ์เล็ก ไม่จำเป็นต้องใช้แต่ให้มีไว้เสมอ

2 changes: 1 addition & 1 deletion src/TridentTD_EasyFreeRTOS32.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class EasyFreeRTOS32 {
EasyFreeRTOS32() {};
void start( TaskFunction_t fn, void * const arg=NULL, const uint32_t StackDepth=2048, uint8_t core_no=1);
inline void start( TaskFunction_t fn, const uint32_t StackDepth, uint8_t core_no) { start( fn, NULL, StackDepth, core_no); }
inline void start( uint8_t core_no, TaskFunction_t fn) { start(fn, NULL, 2048, core_no) }
inline void start( uint8_t core_no, TaskFunction_t fn) { start( fn, NULL, 2048, core_no); }
inline void start( uint8_t core_no, const uint32_t StackDepth, TaskFunction_t fn ) { start( fn, NULL, StackDepth, core_no); }

void stop();
Expand Down

0 comments on commit d9012c7

Please sign in to comment.