Created
November 18, 2014 09:59
-
-
Save yoneken/f65aff28eb277995dc31 to your computer and use it in GitHub Desktop.
【C言語】Intel EdisonでPWM出力 ref: http://qiita.com/yoneken/items/ee0735cb42239750ee8b
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CC = gcc | |
MRAALIBS = -lmraa | |
.PHONY: all clean pwm | |
all: pwm | |
clean: | |
rm -f ./*.o | |
rm -f pwm | |
pwm: pwm.o | |
$(CC) -O4 $(MRAALIBS) -o $@ $^ | |
%.o: %.c | |
$(CC) -Wall -g -c $< |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <syslog.h> | |
#include <mraa.h> | |
int main(int argc, char *argv[]) | |
{ | |
mraa_result_t ret; | |
mraa_init(); | |
ret = mraa_set_log_level(LOG_DEBUG); | |
fprintf(stdout, "Hello mraa.\nVersion: %s\n", mraa_get_version()); | |
mraa_pwm_context pwm; | |
// The physical pin mapping is defined at | |
// https://github.com/intel-iot-devkit/mraa/blob/master/docs/edison.md | |
// | |
// For example, | |
// MRAA Number(20) => Physical Pin(J18-7) | |
pwm = mraa_pwm_init(20); | |
if(pwm == NULL){ | |
return 1; | |
} | |
mraa_pwm_period_us(pwm, 15*1000); // 15[ms] | |
mraa_pwm_enable(pwm, 1); | |
int i; | |
for(i=0;i<20;i++){ | |
mraa_pwm_write(pwm, 0.05*i); | |
usleep(1000*1000); // 1[s] | |
float out = mraa_pwm_read(pwm); | |
fprintf(stdout, "PWM0 : %f\n", out); | |
} | |
mraa_deinit(); | |
return ret; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment