3017 views|6 replies

2

Posts

0

Resources
The OP
 

The running water lamp has realized the left, right, left and right, and pause functions. It still lacks the fast and low speed functions. I don’t know how to add them. [Copy link]

#include<reg51.h>
sbit key1=P3^0;
sbit key2=P3^1;
unsigned char dat1[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
unsigned char dat2[ 8]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
unsigned char dat3[15]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,0xbf,0xdf,0xef ,0xf7,0xfb,0xfd,0xfe};
unsigned char MODE=0,stu=0,num;
void delay(unsigned int x);
void keyscan(void);
void main(void)
{
while(1)
{
keyscan() ;
switch(MODE)
{
case 0:if(stu) {P0=dat1[num];num++;num%=8;}break;
case 1:if(stu) {P0=dat2[num];num++;num% =8;}break;
case 2:if(stu) {P0=dat3[num];num++;num%=15;}break;
}
delay(100);
}
}
void delay(unsigned int x)
{
unsigned int i ,j;
for(i=0;i<x;i++)
{
for(j=0;j<333;j++);
}
}
void keyscan(void)
{
if(key1==0)
{
delay(10);
if(key1==0)
{
MODE++;
MODE%=3;
num=0;
while(key1==0);
}
}
if(key2==0)
{
delay(10);
if(key2==0)
{
stu++;
stu%=2;
while(key2==0);
}
}
}

This post is from 51mcu

Latest reply

You can set a threshold, for example, if the button is not released after one second, It enters an infinite loop, and the acceleration function is executed in this infinite loop. The condition for jumping out of this loop is to release the button. If you press it briefly, it will not enter this cycle and will have no effect on your original functions.   Details Published on 2021-5-19 09:01
 

2

Posts

0

Resources
2
 
And it can only be controlled with two buttons. I hope you can help me modify it.
This post is from 51mcu

Comments

Your point here is that you need to use two buttons to control more than two functions, right? You can consider long pressing the button to achieve fast and slow functions, such as long pressing the right button for fast, and long pressing the left button for slow, but it may be more laborious hahaha  Details Published on 2021-5-19 09:01
Your point here is that you need to use two buttons to control more than two functions, right? You can consider long pressing the button to achieve fast and slow functions, such as long pressing the right button for fast, and long pressing the left button for slow, but it may be more laborious hahaha  Details Published on 2021-5-19 08:56
 
 
 

4

Posts

0

Resources
3
 

Isn’t it possible to directly change the delay size to achieve low-speed and fast functions?

This post is from 51mcu
 
 
 

6593

Posts

0

Resources
4
 

If PWM is not used to implement pipelining

If you want to make the running water lamp slower, increase the delay.

vice versa

This post is from 51mcu
 
 
 

1w

Posts

204

Resources
5
 

You can modify the lighting frequency. From your code, it would be more convenient to adjust the delay directly.

This post is from 51mcu
Add and join groups EEWorld service account EEWorld subscription account Automotive development circle
 
 
 

824

Posts

3

Resources
6
 
This post was last edited by 1nnocent on 2021-5-19 08:57
Microcontroller Xiaobai published on 2021-5-18 12:16 and can only be controlled with two buttons. I hope you can help me modify it.

The key point here is that you need to use two buttons to control more than two functions, right?

You can consider long-pressing the buttons to achieve fast and low-speed functions. For example, the right button is fast when long-pressed, and the left button is low-speed when long-pressed. It may be more labor-intensive hahaha

This post is from 51mcu
 
 
 

824

Posts

3

Resources
7
 
[url=forum.php?mod=redirect&goto=findpost&pid=3063316&ptid=1165931]MCU Xiaobai published on 2021-5-18 12:16[ /url] And it can only be controlled with two buttons. I hope you can help me modify it

You can set a threshold, for example, if the button is not released after one second,

It enters an infinite loop, and the acceleration function is executed in this infinite loop.

The condition for jumping out of this loop is to release the button.

If you press it briefly, it will not enter this cycle and will have no effect on your original functions.

This post is from 51mcu
 
 
 

Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list