/
application.cpp
67 lines (61 loc) · 1.77 KB
/
application.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
* File: Esp SDK Hardware PWM demo
* Original Author: https://github.com/hrsavla
*
* This HardwarePWM library enables Sming framework user to use ESP SDK PWM API
* Period of PWM is fixed to 1000ms / Frequency = 1khz
* Duty at 100% = 22222. Duty at 0% = 0
* You can use function setPeriod() to change frequency/period.
* Calculate the Duty as per the formulae give in ESP8266 SDK
* Duty = (Period *1000)/45
*
* PWM can be generated on upto 8 pins (ie All pins except pin 16)
* Created on August 17, 2015, 2:27 PM
*/
#include <user_config.h>
#include <SmingCore/SmingCore.h>
#include <HardwarePWM.h>
uint8_t pins[8] = { 4, 5, 0, 2, 15, 13, 12, 14 }; // List of pins that you want to connect to pwm
HardwarePWM HW_pwm(pins, 8);
Timer procTimer;
int32 i = 0;
int32 inc = 1000;
bool countUp = true;
void doPWM() {
if (countUp == true) {
i += inc;
if (i >= 22222) {
i = 22222;
countUp = false;
}
} else {
i -= inc;
if (i <= 0) {
i = 0;
countUp = true;
}
}
HW_pwm.analogWrite(12, i); // GPIO12 (D6)
Serial.print("current var = ");
Serial.print(i);
Serial.println();
}
void init() {
Serial.begin(SERIAL_BAUD_RATE); // 115200 by default
Serial.systemDebugOutput(true); // Enable debug output to serial
// WIFI not needed for demo. So disabling WIFI.
WifiStation.enable(false);
WifiAccessPoint.enable(false);
// Setting PWM values on 8 different pins
HW_pwm.analogWrite(4, 22222);
HW_pwm.analogWrite(5, 11111);
HW_pwm.analogWrite(0, 22222);
HW_pwm.analogWrite(2, 11111);
HW_pwm.analogWrite(15, 22222);
HW_pwm.analogWrite(13, 11111);
HW_pwm.analogWrite(12, 22222);
HW_pwm.analogWrite(14, 11111);
debugf("PWM output set on all 8 Pins. Kindly check...");
debugf("Now Pin 2 will go from 0 to VCC to 0 in cycles.");
procTimer.initializeMs(100, doPWM).start();
}