raspberrypi:wiringpi:softpwm
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| raspberrypi:wiringpi:softpwm [2017/01/27 19:43] – created aistis | raspberrypi:wiringpi:softpwm [2017/02/11 13:51] (current) – aistis | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | Impulso pločio moduliacija (Pulse-width modulation) PWM - skirta jeigu norime | ||
| + | simuliuoti stiprėjantį arba silpstantį signalą. Tinka LED Šviesumui reguliuoti arba motoro | ||
| + | sukimosi greitumui reguliuoti | ||
| + | |||
| + | Kodas žemiau didina intensyvumą nuo 0 iki 100 | ||
| <code c> | <code c> | ||
| #include < | #include < | ||
| Line 5: | Line 10: | ||
| int main (void) | int main (void) | ||
| { | { | ||
| - | // | ||
| wiringPiSetupGpio(); | wiringPiSetupGpio(); | ||
| - | | + | softPwmCreate(2, |
| - | // | + | |
| - | //pinMode (2, PWM_OUTPUT ) ; | + | |
| - | | + | |
| - | // | + | |
| for (int i=0; | for (int i=0; | ||
| { | { | ||
| - | // | ||
| softPwmWrite (2, i); | softPwmWrite (2, i); | ||
| delay (20) ; | delay (20) ; | ||
| - | // | ||
| } | } | ||
| return 0 ; | return 0 ; | ||
| } | } | ||
| + | </ | ||
| + | kodas zemiau spaudant q ir w galima reguliuoti intensyvumą | ||
| + | <code c> | ||
| + | # | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | const int pin = 21; | ||
| + | |||
| + | int main(void){ | ||
| + | int c; | ||
| + | static struct termios oldt, newt; | ||
| + | tcgetattr( STDIN_FILENO, | ||
| + | newt = oldt; | ||
| + | newt.c_lflag &= ~(ICANON | ECHO); | ||
| + | tcsetattr( STDIN_FILENO, | ||
| + | | ||
| + | wiringPiSetupGpio(); | ||
| + | pinMode(pin, | ||
| + | softPwmCreate(pin, | ||
| + | | ||
| + | int p = 0; | ||
| + | |||
| + | printf(" | ||
| + | printf(" | ||
| + | while((c=getchar())!= ' | ||
| + | { | ||
| + | if (c == ' | ||
| + | p ++; | ||
| + | printf(" | ||
| + | softPwmWrite (pin, p); | ||
| + | } | ||
| + | if (c == ' | ||
| + | p --; | ||
| + | printf(" | ||
| + | softPwmWrite (pin, p); | ||
| + | } | ||
| + | delay (20) ; | ||
| + | } | ||
| + | |||
| + | tcsetattr( STDIN_FILENO, | ||
| + | return 0; | ||
| + | } | ||
| </ | </ | ||
raspberrypi/wiringpi/softpwm.1485538992.txt.gz · Last modified: by aistis
