Anda di halaman 1dari 2

1 #include <Arduino_FreeRTOS.

h>
2
3 // tentukan aplikasi Realtimenya
4 void TaskBlink( void *pvParameters );
5 void TaskLampuRedup( void *pvParameters );
6 void TaskPotensio( void *pvParameters );
7
8
9 void setup() {
10 Serial.begin(9600);
11
12 // Setting loop program yang berjalan sendiri-sendiri
13 xTaskCreate(
14 TaskBlink
15 , (const portCHAR *)"Blink" //nama loop
programnya
16 , 128 // ukuran stack
17 , NULL
18 , 3 //prioritas ke 3
19 , NULL );
20
21
22 xTaskCreate(
23 TaskLampuRedup
24 , (const portCHAR *) "PWM" //nama loop
programnya
25 , 128 // ukuran stack
26 , NULL
27 , 2 // Prioritas ke 2
28 , NULL );
29
30 xTaskCreate(
31 TaskPotensio
32 , (const portCHAR *) "ADC" //nama loop
programnya
33 , 128 // ukuran stack
34 , NULL
35 , 1 // Prioritas ke 1
36 , NULL );
37
38 }
39
40 void loop(){
41 // kosong
42 }
43
44
45 /*---------------------- programnya
---------------------*/
46
47 void TaskBlink(void *pvParameters) { // loop
program Blink.
48 (void) pvParameters;
49
50
51 pinMode(13, OUTPUT); // kaki led
52
53 while (1) {
54 digitalWrite(13, LOW);
55 Serial.println("LED 13 on");
56 vTaskDelay( 1000 / portTICK_PERIOD_MS );
57 digitalWrite(13, HIGH);
58 Serial.println("LED 13 off");
59 vTaskDelay( 1000 / portTICK_PERIOD_MS );
60 }
61 }
62
63 void TaskLampuRedup(void *pvParameters) { // loop
program lampu redup
64 (void) pvParameters;
65
66 int upup=0;
67 while (1) {
68 upup+=50;
69 analogWrite(9,upup);
70 Serial.print("Lampu value = ");
71 Serial.println(upup);
72 vTaskDelay(20); // 1 tick = 300ms, jika 20,
berarti?
73 if(upup>255) upup=0;
74 }
75 }
76
77 void TaskPotensio(void *pvParameters) { // loop
program baca potensio
78 (void) pvParameters;
79
80
81 while (1) {
82 // read the input on analog pin 0:
83 int sensorValue = analogRead(A0);
84 // print out the value you read:
85 Serial.print("Potensio = ");
86 Serial.println(sensorValue);
87 vTaskDelay(20); // one tick delay (300ms) in
between reads for stability
88 }
89 }

Anda mungkin juga menyukai