我想编一个红绿灯程序,先是红灯亮10秒,然后是绿灯亮20秒,再是黄灯亮5秒,然后依次再从红灯开始循环,谁要是有这样的程序代码,请告诉我

解决方案 »

  1.   

    dim timeCount as long   '如果灯亮时间长可以使用该变量计时
    dim lampChange as long  '判断灯的状态 0-红 1-绿 2-黄
    dim lampTime(2) as long     '灯亮的时间
    '使用 timer 控件timer1
    form_load()
      '初始化时间间隔
      lampTime(0)=10
      lampTime(1)=20
      lampTime(2)=5
      '初始化时间计量
      timeCount=0
      lampChange=0
      timer1.Interval=1000   '一秒计时
      timer1.enable=true
    end sub
    timer1_timer()
     timecount=timecount+1  '每秒累加
     if lampChange<2 then
        if timecount=lampTime(lampChange) then  ‘如果时间到当前灯的亮时长
           lampChange=lampChange+1
           timecount=0
           call changeLamp(lampChange)   ’处理灯的转换
        else
           '未到时间不处理
        endif
     else
        if timecount=lampTime(lampChange) then  ‘如果时间到当前灯的亮时长
           lampChange=0
           timecount=0
           call changeLamp(lampChange)   ’处理灯的转换
        else
           '未到时间不处理
        endif
     end if
     
     
    end sub
    private sub changeLamp(lampChange as long)
      select case lampChange 
      case 0
         ’红亮的代码
      case 1
         ’绿亮的代码
      case 2
         ’黄亮的代码
      case else 
         ’例外情况的处理
      end select
    end sub
      

  2.   

    我大三实习就做了这个程序,不过我们还要求硬件实现,我这有代码啊,连汇编的程序都有,[email protected]
      

  3.   

    直接用MCU+ASM做就可以了,用不上VB吧