当前位置:网站首页>Experiment 2 LED button PWM 2021/11/15
Experiment 2 LED button PWM 2021/11/15
2022-06-30 08:01:00 【emplace_ back】
Run this command to stop led flashing
/etc/rc.d/init.d/leds stop
led
#include<stdio.h>
#include<stdlib.h>
#include<fcntl.h>
#include<time.h>
int main() {
int fd,i;
fd=open("/dev/leds",O_WRONLY);
if(fd<0) {
printf("Open leds error!\n");
exit(1);
}
for(i=0;i<4;i++) ioctl(fd,0,i);
for(;;) {
for(i=0;i<4;i++)
ioctl(fd,0,i);
for(i=0;i<4;i++) {
ioctl(fd,1,i);
sleep(1);
}
}
close(fd);
return 0;
}
button
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<fcntl.h>
int main() {
int fd,i;
char key[4]={
'0'};
fd=open("/dev/buttons",O_RDONLY);
if(fd<0) {
printf("Open buttons error!\n");
exit(1);
}
for(;;) {
read(fd,key,sizeof(key));
for(i=0;i<4;i++) {
usleep(50000);
for(i=0;i<4;i++)
if(key[i]=='1') printf("key%d\n",i+1);
}
}
close(fd);
return 0;
}
pwm
#include<stdio.h>
#include<stdlib.h>
#include<fcntl.h>
#include<time.h>
int main() {
int fd,frq=2000;
fd=open("/dev/pwm",O_RDONLY);
if(fd<0) {
printf("Open pwm error!\n");
exit(1);
}
ioctl(fd,1,frq);
sleep(3);
ioctl(fd,0);
close(fd);
return 0;
}
Ctrl + C The end of the process
Ctrl + Z Pause the process
improvement
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
int main(void) {
int fd;
char key[4]={
'0'};
fd = open("/dev/buttons",O_RDONLY);
if (fd<0) {
printf("ERROR\n");
exit(1);
}
for (;;) {
char now[4];
int cnt=0;
int i;
read(fd,now,sizeof now);
for (i=0,cnt=0;i<4;i++) {
if (key[i]!=now[i]) {
key[i] = now[i];
printf("key%d is ",i+1);
if(key[i]=='1') printf("down");
else printf("up");
cnt++;
}
}
if (cnt) printf("\n");
}
close(fd);
return 0;
}
边栏推荐
- Efga design open source framework openlane series (I) development environment construction
- At the age of 25, I started to work in the Tiankeng industry with buckets. After going through a lot of hardships to become a programmer, my spring finally came
- Deep learning -- using word embedding and word embedding features
- Solve the linear equation of a specified point and a specified direction
- 安科瑞高等学校校园建筑节能监管系统建设
- CRM&PM如何帮助企业创造最优销售绩效
- February 14, 2022 [reading notes] - life science based on deep learning Chapter 2 Introduction to deep learning (Part 1)
- 回文子串、回文子序列
- 【Tensorflow-gpu】window11下深度学习环境搭建
- ACM. Hj48 delete the node with the specified value from the one-way linked list ●●
猜你喜欢

鲸探NFT数字臧品系统开发技术分享

微信小程序使用vant weapp报错

深度学习——循环神经网络

Use of nested loops and output instances
![Arm debug interface (adiv5) analysis (I) introduction and implementation [continuous update]](/img/30/375860665aa1cc761adffc0e782744.jpg)
Arm debug interface (adiv5) analysis (I) introduction and implementation [continuous update]

AcrelEMS能效管理平台为高层小区用电安全保驾护航

冰冰学习笔记:快速排序

342 maps covering exquisite knowledge, one of which is classic and pasted on the wall

Simple application of generating function -- integer splitting 2

深度学习——使用词嵌入and词嵌入特征
随机推荐
342 maps covering exquisite knowledge, one of which is classic and pasted on the wall
直击产业落地 | 飞桨重磅推出业界首个模型选型工具
Intersection of two lines
Conversion between basic data types in go data types
mysql无法连接内网的数据库
Full stack performance testing theory - Summary
跳槽字节跳动很难嘛?掌握这些技巧,你也能轻松通过
奇迹MU服务器租用选择 真实好用 稳定不卡 还能防入侵
NMOS model selection
How to handle the expired data of redis and what are the elimination mechanisms?
深度学习——使用词嵌入and词嵌入特征
架构实战营模块 5 作业
Miracle Mu server rental selection is real and easy to use, stable and intrusion proof
November 22, 2021 [reading notes] - bioinformatics and functional genomics (Chapter 5, section 4, hidden Markov model)
C. Fishingprince Plays With Array
F12 packet capture is used for the whole process analysis of postman interface test
Efga design open source framework openlane series (I) development environment construction
Why don't you know what to do after graduation from university?
Combinatorial mathematics Chapter 2 Notes
Palindrome substring, palindrome subsequence