Skip to content

Commit 70e0e5d

Browse files
author
kolban
committed
Wed Feb 1 22:32:43 CST 2017
1 parent d22ed78 commit 70e0e5d

File tree

5 files changed

+125
-11
lines changed

5 files changed

+125
-11
lines changed

Makefile

-11
This file was deleted.

hardware/LEDs/ledDim.c

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#include <esp_log.h>
2+
#include <freertos/FreeRTOS.h>
3+
#include <freertos/task.h>
4+
#include <driver/ledc.h>
5+
#include "sdkconfig.h"
6+
7+
static char tag[] = "led_dim";
8+
9+
10+
11+
void task_led_dim(void *ignore) {
12+
int bitSize = 15;
13+
int minValue = 0; // micro seconds (uS)
14+
int maxValue = 1<<bitSize; // micro seconds (uS)
15+
int sweepDuration = 4000; // milliseconds (ms)
16+
int duty = (1<<bitSize) * minValue / 20000 ;
17+
int direction = 1; // 1 = up, -1 = down
18+
int valueChangeRate = 20; // msecs
19+
20+
ESP_LOGD(tag, ">> task_led_dim");
21+
ledc_timer_config_t timer_conf;
22+
timer_conf.bit_num = LEDC_TIMER_15_BIT;
23+
timer_conf.freq_hz = 300;
24+
timer_conf.speed_mode = LEDC_HIGH_SPEED_MODE;
25+
timer_conf.timer_num = LEDC_TIMER_0;
26+
ledc_timer_config(&timer_conf);
27+
28+
ledc_channel_config_t ledc_conf;
29+
ledc_conf.channel = LEDC_CHANNEL_0;
30+
ledc_conf.duty = duty;
31+
ledc_conf.gpio_num = 4;
32+
ledc_conf.intr_type = LEDC_INTR_DISABLE;
33+
ledc_conf.speed_mode = LEDC_HIGH_SPEED_MODE;
34+
ledc_conf.timer_sel = LEDC_TIMER_0;
35+
ledc_channel_config(&ledc_conf);
36+
37+
int changesPerSweep = sweepDuration / valueChangeRate;
38+
int changeDelta = (maxValue-minValue) / changesPerSweep;
39+
int i;
40+
ESP_LOGD(tag, "sweepDuration: %d seconds", sweepDuration);
41+
ESP_LOGD(tag, "changesPerSweep: %d", changesPerSweep);
42+
ESP_LOGD(tag, "changeDelta: %d", changeDelta);
43+
ESP_LOGD(tag, "valueChangeRate: %d", valueChangeRate);
44+
while(1) {
45+
for (i=0; i<changesPerSweep; i++) {
46+
if (direction > 0) {
47+
duty += changeDelta;
48+
} else {
49+
duty -= changeDelta;
50+
}
51+
ledc_set_duty(LEDC_HIGH_SPEED_MODE, LEDC_CHANNEL_0, duty);
52+
ledc_update_duty(LEDC_HIGH_SPEED_MODE, LEDC_CHANNEL_0);
53+
vTaskDelay(valueChangeRate/portTICK_PERIOD_MS);
54+
}
55+
direction = -direction;
56+
ESP_LOGD(tag, "Direction now %d", direction);
57+
} // End loop forever
58+
59+
vTaskDelete(NULL);
60+
}

hardware/servos/servoSweep.c

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#include <esp_log.h>
2+
#include <freertos/FreeRTOS.h>
3+
#include <freertos/task.h>
4+
#include <driver/ledc.h>
5+
#include "sdkconfig.h"
6+
7+
static char tag[] = "servo1";
8+
9+
10+
11+
void task_servoSweep(void *ignore) {
12+
int bitSize = 15;
13+
int minValue = 500; // micro seconds (uS)
14+
int maxValue = 2500; // micro seconds (uS)
15+
int sweepDuration = 1500; // milliseconds (ms)
16+
int duty = (1<<bitSize) * minValue / 20000 ;
17+
int direction = 1; // 1 = up, -1 = down
18+
int valueChangeRate = 20; // msecs
19+
20+
ESP_LOGD(tag, ">> task_servo1");
21+
ledc_timer_config_t timer_conf;
22+
timer_conf.bit_num = LEDC_TIMER_15_BIT;
23+
timer_conf.freq_hz = 50;
24+
timer_conf.speed_mode = LEDC_HIGH_SPEED_MODE;
25+
timer_conf.timer_num = LEDC_TIMER_0;
26+
ledc_timer_config(&timer_conf);
27+
28+
ledc_channel_config_t ledc_conf;
29+
ledc_conf.channel = LEDC_CHANNEL_0;
30+
ledc_conf.duty = duty;
31+
ledc_conf.gpio_num = 16;
32+
ledc_conf.intr_type = LEDC_INTR_DISABLE;
33+
ledc_conf.speed_mode = LEDC_HIGH_SPEED_MODE;
34+
ledc_conf.timer_sel = LEDC_TIMER_0;
35+
ledc_channel_config(&ledc_conf);
36+
37+
int changesPerSweep = sweepDuration / valueChangeRate;
38+
int changeDelta = (maxValue-minValue) / changesPerSweep;
39+
int i;
40+
ESP_LOGD(tag, "sweepDuration: %d seconds", sweepDuration);
41+
ESP_LOGD(tag, "changesPerSweep: %d", changesPerSweep);
42+
ESP_LOGD(tag, "changeDelta: %d", changeDelta);
43+
ESP_LOGD(tag, "valueChangeRate: %d", valueChangeRate);
44+
while(1) {
45+
for (i=0; i<changesPerSweep; i++) {
46+
if (direction > 0) {
47+
duty += changeDelta;
48+
} else {
49+
duty -= changeDelta;
50+
}
51+
ledc_set_duty(LEDC_HIGH_SPEED_MODE, LEDC_CHANNEL_0, duty);
52+
ledc_update_duty(LEDC_HIGH_SPEED_MODE, LEDC_CHANNEL_0);
53+
vTaskDelay(valueChangeRate/portTICK_PERIOD_MS);
54+
}
55+
direction = -direction;
56+
ESP_LOGD(tag, "Direction now %d", direction);
57+
} // End loop forever
58+
59+
vTaskDelete(NULL);
60+
}

pwm/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
### See also
2+
* hardware/servos

rmt/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### See also
2+
* hardware/neopixels
3+
* hardware/infrared

0 commit comments

Comments
 (0)