와이프가 면 삶을때 시계보고 맞추기 불편하다고 해서 요리할때 사용할수 있는 타이머를 만들어봤습니다.
시간이 정확하진 않겠지만 그리 중요하지 않으니 무시했습니다 ^^;
동작은 SW2 버튼으로 시간을 설정하고 SW1 버튼을 누르면 시계가 거꾸로 가고, 시간이 0이 되면 알람이 울리는 것입니다.
ATTiny26L, 스피커, 스위치 두개, 풀업저항두개, 가변저항 10k ohm, LCD 입니다.
상당히 엉성하네요. ㅠㅠ
어떻게 깔끔하게좀 안될까요?
SW2 : +30 sec
1번 스위치를 한번 누르면 시계가 동작하고 다시 한번 누르면 멈추면서 원래 설정한 시간으로 돌아옵니다.
1번 스위치를 길게 누르면 시간이 0으로 리셋됩니다.
2번 스위치를 한번 누를때마다 설정시간이 30초씩 증가합니다.
옆에 있는 전원 스위치를 없에고 싶었으나 sleep모드를 어떻게 쓰는건지 몰라 포기하고 다음으로 미루었습니다.
작업중 가장 어려웠던 점은 tiny칩의 메모리가 너무 적다는것입니다.
아래 소스보면 아시겠지만 몇줄 안되는데 메모리를 100% 다 사용하더군요.
그래서 소스를 이리 바꾸고 저리 바꾸고 해서 겨우 구겨넣었습니다.
기능을 더 넣고 싶어도 생략하고 최대한 간단하게 넣었습니다.
별건 아니지만 써먹을수 있는걸 만들었다고 생각하니 흐뭇하군요.
얼마나 유용하게 써먹어 줄지는 미지수지만요. ㅎㅎㅎ
$regfile = "attiny26.dat"
$crystal = 4000000
'$sim
$hwstack = 32 ' default use 32 for the hardware stack
$swstack = 10 ' default use 10 for the SW stack
$framesize = 40 ' default use 40 for the frame space
Dim Lsec0 As Long , Lsec1 As Long , Lsec2 As Long , Ltmp As Long , Lmin As Long
Dim Startcooktimer As Byte , Presstime As Long , J As Byte
Dim Idletime As Long
Config Lcdpin = Pin , Db4 = Porta.3 , Db5 = Porta.2 , Db6 = Porta.1 , Db7 = Porta.0 , E = Porta.6 , Rs = Porta.7
Config Portb = Input
Initlcd
Cls
Cursor Off
'Locate 1 , 1 : Lcd "Cooking"
'Locate 2 , 2 : Lcd "Timer"
'Waitms 1000
Lsec0 = 120
Main:
Startcooktimer = 0
Gosub Initcooktimer
Do
' SW 6 : Start/Stop/Reset
If Pinb.6 = 1 Then
Waitms 20
If Pinb.6 = 1 And Lsec0 > 0 Then
Waitms 200
If Pinb.6 = 0 Then
Startcooktimer = 1
Exit Do
End If
Waitms 400
If Pinb.6 = 0 Then
Startcooktimer = 1
Exit Do
End If
Waitms 400
' Reset
If Pinb.6 = 1 Then
Lsec0 = 0
Gosub Initcooktimer
Waitms 500
End If
End If
End If
' SW 5 : +30 sec
If Pinb.5 = 1 Then
Waitms 20
If Pinb.5 = 1 Then
Lsec0 = Lsec0 + 30
If Lsec0 >= 60000 Then
Lsec0 = 0
End If
Gosub Initcooktimer
Waitms 400
End If
'Idletime = 0
End If
Loop Until Startcooktimer = 1
'run timer
Do
Decr Lsec1
Gosub Displaycooktimer
For J = 1 To 20
If Pinb.6 = 1 Then
Waitms 20
If Pinb.6 = 1 Then
Do
Loop Until Pinb.6 = 0
Startcooktimer = 0
Gosub Initcooktimer
End If
End If
Waitms 50
Next J
If Lsec1 <= 0 Then
Gosub Playsound
Exit Do
End If
Loop Until Startcooktimer = 0
Goto Main
Playsound:
Sound Portb.4 , 80 , 500
Waitms 100
Sound Portb.4 , 80 , 600
Waitms 100
Sound Portb.4 , 80 , 700
Waitms 500
If Pinb.6 = 1 Then
Waitms 20
If Pinb.6 = 1then
Do
Loop Until Pinb.6 = 0
Return
End If
End If
If Pinb.5 = 1 Then
Waitms 20
If Pinb.5 = 1 Then
Do
Loop Until Pinb.5 = 0
Return
End If
End If
Goto Playsound
Return
Initcooktimer:
Lsec1 = Lsec0
Gosub Displaycooktimer
Return
Displaycooktimer:
Cls
Lmin = Lsec1 / 60
Ltmp = Lmin * 60
Lsec2 = Lsec1 - Ltmp
Locate 1 , 1 : Lcd Lmin
Locate 1 , 3 : Lcd ":"
Locate 1 , 5 : Lcd Lsec2
If Startcooktimer = 1 Then
Locate 2 , 1 : Lcd "Start"
Else
Locate 2 , 1 : Lcd "Stop "
End If
Return
'Arduino/AVR > 3. AVR 프로젝트' 카테고리의 다른 글
| ATTiny26을 이용한 어린이용 반짝이 운동화 만들기 (20) | 2009.08.11 |
|---|---|
| ATTiny26 Switch, LED 예제 (0) | 2009.06.22 |