-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpwmwrite.ion
More file actions
19 lines (17 loc) · 828 Bytes
/
pwmwrite.ion
File metadata and controls
19 lines (17 loc) · 828 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*
@LANG: ARDUINO
@USAGE: A function that produce an analog voltage on a non-PWM pin.
@PARAMETERS: takes non-PWM pin number and value between 0 [LOW] to 255 [HIGH]
@Description: The voltage value taking from a pin is the average value of the period.
Using that we can get an average value from a non-PWM enabled arduino pin by manipulating the duty cycle of the HIGH and LOW voltage with a very small period 100 microsecond.
*/
void PWMWrite(int pin, int volt){
int timeHIGH = ((volt/255) * 100 ) * 100; //getting the percentage of the HIGH voltue and multiplying it by 100 MICROSECOND
float timeLOW = 100 - timeHIGH;
while(1){ //Infinit loop to supply the needed voltage without stopping.
digitalWrite(pin,HIGH);
delayMicroseconds(timeHIGH);
digitalWrite(pin,LOW);
delayMicroseconds(timeLOW);
}
}