大家来集思广益,一起讨论,一起进步呀。搞不懂啊,一点都不会。
4条回答 默认 最新
- CodeBytes 2023-02-07 21:20关注
该回答引用ChatGPT
基本功能:
#include <stdio.h> #include <stdlib.h> #include <time.h> #define OFF 0 #define LOW 1 #define MEDIUM 2 #define HIGH 3 int fan_speed = OFF; // 初始风速 int timer = 0; // 定时器 // 设置风速 void set_fan_speed(int speed) { fan_speed = speed; printf("当前风速:%d\n", fan_speed); } // 设置定时器 void set_timer(int time) { timer = time; printf("设置定时:%d\n", timer); } // 显示剩余定时时间 void show_remaining_time() { while (timer > 0) { printf("剩余时间:%d\n", timer); sleep(1); timer--; } fan_speed = OFF; printf("定时结束,当前风速:%d\n", fan_speed); } int main() { int choice; while (1) { printf("菜单:\n"); printf("1. 设置风速(1-LOW,2-MEDIUM,3-HIGH)\n"); printf("2. 设置定时器(以秒为单位)\n"); printf("3. 退出\n"); scanf("%d", &choice); switch (choice) { case 1: printf("请输入风速:"); scanf("%d", &choice); switch (choice) { case 1: set_fan_speed(LOW); break; case 2: set_fan_speed(MEDIUM); break; case 3: set_fan_speed(HIGH); break; default: printf("无效的风速\n"); } break; case 2: printf("请输入定时时间:"); scanf("%d", &timer); set_timer(timer); show_remaining_time(); break; case 3: return 0; default: printf("无效的选项\n"); } } return 0; }
PWM功能:
#include <stdio.h> int main() { int mode; printf("Enter mode (1-4): "); scanf("%d", &mode); switch(mode) { case 1: printf("PWM duty cycle: 20%%\n"); break; case 2: printf("PWM duty cycle: 50%%\n"); break; case 3: printf("PWM duty cycle: 80%%\n"); break; case 4: printf("PWM duty cycle: 100%%\n"); break; default: printf("Invalid mode\n"); break; } return 0; }
数码管显示功能:
#include <stdio.h> #include <unistd.h> int main() { int mode; int time = 180; printf("Enter mode (1-4): "); scanf("%d", &mode); while (time >= 0) { printf("Mode: "); switch(mode) { case 1: printf("A\n"); printf("PWM duty cycle: 20%%\n"); break; case 2: printf("B\n"); printf("PWM duty cycle: 50%%\n"); break; case 3: printf("C\n"); printf("PWM duty cycle: 80%%\n"); break; case 4: printf("D\n"); printf("PWM duty cycle: 100%%\n"); break; default: printf("Invalid mode\n"); break; } printf("Time remaining: %d\n", time); time--; sleep(1); } return 0; }
LED显示部分:
#include <stdio.h> #include <unistd.h> int main() { int interval = 800; int input; while (1) { printf("LED On\n"); usleep(interval * 1000); printf("LED Off\n"); usleep(interval * 1000); printf("Enter 1 to increase interval, -1 to decrease interval, 0 to exit: "); scanf("%d", &input); if (input == 1) { interval += 200; } else if (input == -1) { interval -= 200; } else if (input == 0) { break; } } return 0; }
解决 2无用
悬赏问题
- ¥15 如何在scanpy上做差异基因和通路富集?
- ¥20 关于#硬件工程#的问题,请各位专家解答!
- ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
- ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
- ¥30 截图中的mathematics程序转换成matlab
- ¥15 动力学代码报错,维度不匹配
- ¥15 Power query添加列问题
- ¥50 Kubernetes&Fission&Eleasticsearch
- ¥15 報錯:Person is not mapped,如何解決?
- ¥15 c++头文件不能识别CDialog