Zedomax DIY125

From Zedomax Wiki

Jump to: navigation, search




HOWTO make a Music syncing Light Orb Alarm Clock


Contents

Intro

Okay, we have seen some really cool Light Orbs while trying to make this Music Syncing Light Orb Alarm Clock.

We started with Tod's creation and soon realize that 1 LED will not be bright enough in slightest light conditions though his Light Orb is tight let us say.

So we checked out RGB lights at Hackedgadgets.com. Which is cool and uses 4 Red, 3 Green, and 3 Blue LEDs.

Well during our google search for Light Orb HOWTOs, we came to the Ambient Devices schematic and their technical notes. Well it says that with the right voltage, you don't need to use resistors.

During our breadboard testing, this proved to be costly. We went through about 20 nice High output LEDs trying to match the forward voltage of LEDs... (Alan, we need more red and green LEDs...hehe)

Well, we tried all kinds of combinations including 3, 4, 5, and 6 LEDs per color. In the end, we found that 100 Ohms with 4 LEDs in series worked pretty well for all the LEDs regardless of their color and forward voltage.

Since we wanted this project to be used with various LEDs, we decided to KISS (Keep It Simple Stupid) our way to the end.

After we made the actual prototype and put the Orb on top, The 4 LEDs in series worked great even in lots of light.

So best thing I think here is to test your LEDs on a breadboard first before soldering them. Even if the rated voltage of the LED says it'd work, we found that sometimes logic does not always work. Burn test your LEDs at least for 20 minutes and make sure they are still working before soldering anything...

With that squared away, let's get back to DIY hacking business here.

We wanted to create a Light Orb that would be a mix of Light Orb, some cheap Piezo music, and an alarm clock. We figured these would do very good Christmas presents for our friends and family.

Parts List

(We used 100 Ohm resistors but you could probably use anywhere between 50 to 150 Ohm resistors)

Total Cost:

Light Orb: about $80 Light Orb with Alarm Clock Function: about $140

Light Orb Schematics

(Yes, I had to goto a Christmas party, so here's a rough sketch!)

Build the CB280 Mini Proto-Board

First, you will need to build a CB280 Mini Proto-Board. Here's the HOWTO:

CB280_Proto-Board_Solder_and_Assembly_HOWTO

Light Orb Mods

First, get the 3 4.7K resistors soldered onto I/O labels P5, P6, P7, and to empty holes as shown here:

Get one of your 2N3904 transistors and solder it on like shown here:

Solder on 2 more transistors:

Solder on 3 100 Ohm resistors to the right side of the resistors as shown here:

You can connect one end of the resistors to the right pin of the transistors as shown here:

Solder on your 4 Red LEDs in series from the 100 Ohm resistor:

Solder on your 4 Green LEDs in series and your 4 Blue LEDs in series too:

You can use one of the LEDs in series pins to connect to the other end of LEDs in series. So connect ground of LED row 1 to LED row 2 and connect ground of LED row 2 to LED row 3.

Splice some wire so it will fit the transistors like shown here and wire all the transistors on the back of the proto-board. This will all go to ground so wire the end to ground.

Solder the 4.7K Ohm resistor coming from P5 to middle pin of the first transistor.

Solder a wire from the 4.7K Ohm resistor on the P6 to middle pin of the second transistor.

Solder a wire from the the 4.7K Ohm resistor on the P7 to middle pin of the third transistor.

Now connect from the end of the LEDs to the DC Jack Positive point, 12V. (We can supply 9 to 24V, but we will use a 12V adaptor here)

Connect a 12V DC adaptor to your Proto-Board and see if it powers up.

Download the program to your CB280. The Program source code is at the end of this HOWTO.

Put a Orb on top of the circuit and you should see colors!

Now if you got to this point and you don't want alarm clock function, you can stop here. But if you want to add the alarm function keep going.


Alarm Clock Mods

Okay, you will need some type of desk drawer thingee or something like it.

Disassemble everthing:

You can take out the center divide with a screwdriver like this:

You should get something like this:


Cut the bottom board you took out earlier so it will fit the frame on top.

Put one of the cut board on top and your proto-board on it.

Make a hole where you will get your LCD cable and some LEDs through:

Solder on the 4pin connector male onto the bottom of the proto-board and you will get something like this:

Solder on 3 Blue LEDs on the bottom of the proto-board next to the male connector:

Solder on a 100 Ohm resistor from the end of the 3 Blue LEDs to ground:

Connect the 4-pin connector to 5V and ground:

Solder on two 4.7K Ohm to P8 and P9 to 5V. This is for the I2C line for the LCD. You need 4.7K Pull-up resistors for the data lines SCL and SDA.

Now connect SCL and SDA to the 4-pin connector and you are almost ready to goto your Christmas party.

Connect the LCD and power it on! (My gf is getting mad becaz of this project but I am almost finshed!!!)



Now connect 2 wires from the bottom of the proto-board on P10 and P11. These will be connected to our push-switches (IO tact switch) .

Here's the IO Tact switches that we will embedd onto our drawer thingee:


Connect the Ground and 5V together on the back of the IO Tact switches:

Drill some holes and fit them on your other half of top board. You can hot-glued them on like we did:

You should have the 4 lines coming from the bottom of your proto-board for the IO Tact switches:

Pull those wires through the holes and wire them to your IO Tact switches:

Hot-glue your LCD on to the frame:

Use screws to screw on the proto-board to the top board:

Hot glue the top boards to the frame and hot glue anything that's not:

Power it on and see if it's working...

You can use a piece of binder like we did to cover over the LEDs, so they will diffuse and mix colors!

Finished Pictures

Source Code

We didn't really have time to finish my project all the way but it works for now... We will have to add some more features next year.

Merry Christmas!

Const Device = CB280
'Define speed for songs
'Set to higher for slower song speed and lower for faster song speed

#define DELAYTIME 100
'Set delay time for Slow mode
#define sdelay 10
Dim num As Byte
	
'PWM3, Song and frequency declarations
Dim oct(9) As String *80
Const Single NOTES= (16.35,17.32,18.35,19.45,20.60,21.83,23.12, 24.50, 25.96, 27.50,29.14, 30.87)					'Octave 0
Const Single BLUES= (16.35,19.45,21.83,23.12,24.50,29.14)
'Jungle Bells Octave 5
		oct(0)="O5,E2,E2,E4,E2,E2,E4,E2,G2,C3,D1,E8,F2,F2,F3,F1!"
		oct(1)="O5,F2,E2,E2,E1,E1,E2,D2,D2,E2,D4,G4,E2,E2,E4,E2,E2,E4,E2,G2,C3,D1,E8!"
		oct(2)="O5,F2,F2,F3,F1,F2,E2,E2,E1,E1,G2,G2,F2,D2,C8!"			
'Jungle Bells Octave 6
		oct(3)="O6,E2,E2,E4,E2,E2,E4,E2,G2,C3,D1,E8,F2,F2,F3,F1!"
		oct(4)="O6,F2,E2,E2,E1,E1,E2,D2,D2,E2,D4,G4,E2,E2,E4,E2,E2,E4,E2,G2,C3,D1,E8!"
		oct(5)="O6,F2,F2,F3,F1,F2,E2,E2,E1,E1,G2,G2,F2,D2,C8!"
'Jungle Bells Octave 4		
		oct(6)="O4,E2,E2,E4,E2,E2,E4,E2,G2,C3,D1,E8,F2,F2,F3,F1!"
		oct(7)="O4,F2,E2,E2,E1,E1,E2,D2,D2,E2,D4,G4,E2,E2,E4,E2,E2,E4,E2,G2,C3,D1,E8!"
		oct(8)="O4,F2,F2,F3,F1,F2,E2,E2,E1,E1,G2,G2,F2,D2,C8!"

'Period for PWM
#define PeriodL 256

'Light RGB declarations
Dim ct As Integer, ct2 As Byte, ct3 As Byte
Dim status1 As Byte, status2 As Byte, status3 As Byte
Dim Arrow As Byte
Dim SoundMode As Byte
Dim AlarmColor As Byte
Dim AlarmPosition As Byte
Dim TimePosition As Byte

SoundMode=3
AlarmColor=0
Arrow=1
AlarmPosition=0
TimePosition=0

Dim sec As Byte, min As Byte, hr As Byte
Dim sec2 As Byte, min2 As Byte, hr2 As Byte
Dim AlarmHr As Byte, AlarmMin As Byte
'Set default alarm to 6 AM.
AlarmHr=6
AlarmMin=0

Dim SleepTime As Integer
Dim Sleep As Byte
Dim MenuMode As Byte
SleepTime= 60 * 30 'Set default Sleep time to 30 minutes it would be 60 * 30 seconds
MenuMode=0 'Main Menu
Sleep=0
'PWM0, PWM1, PWM2, and PWM3 correspond to P5, P6, P7, and P19 of CB280
Output 5
Output 6
Output 7
Output 19

'Pushbutton inputs P10 and P11, set them to inputs
Input 10
Input 11
	
'Reset Variables
ct=200
ct2=0
ct3=0

status1=0
status2=0
status3=0

Red 0
Green 0
Blue 0
	

	'	PlayString oct(2)
		Set Display 2,0,0,128
		Cls
		Delay 200
		Locate 0,0
		Print "Zedomax Light Orb"
		Locate 5,1
		Print "Alarm Clock"
		Delay 800
		MainMenu
		
On Timer(10) Gosub here

Do

'Alarm 1000
'If Arrow at Mode
	If SoundMode=0 Then
		Pwmoff 3
		Pwmoff 0
		Pwmoff 1
		Pwmoff 2
	Elseif SoundMode=1 Then
		'Play Jingle Bells
		For ct=0 To 8
			PlayString oct(ct)
		Next
	Elseif SoundMode=2 Then
		RunBluesRandom
	Elseif SoundMode=3 Then		
		Slow
	End If
	
	
	'	PlayString oct(1)
'		Next
'Slow


Loop

here:

PrintTime 0

If hr=AlarmHr And min=AlarmMin And sec=0 Then
	SoundMode=3
End If

	If Sleep=1 Then
			Locate 0,1
			Print "                   "
			Locate 0,1
			Print Dec SleepTime, " seconds left..."
	End If
	
   If In(10)=0 Then
		Debug "10!",Cr
		MaxBEEP	
		Delay 100
		
		If MenuMode=0 Then
			Locate 15,Arrow
			Print "  "
			Incr Arrow
			If Arrow=4 Then Arrow=1
			PrintArrow
		Elseif MenuMode=1 Then
				Locate 0,1
				Print "                   "
				Locate 0,1
				Print Dec SleepTime, " seconds left..."
				SoundMode=3
				Sleep=1
				MenuMode=2
				
		Elseif MenuMode=2 Then
	 			Sleep=0
				MenuMode=0
				SoundMode=0
				MainMenu
		Elseif MenuMode=3 Then
			
			If AlarmPosition =0 And TimePosition=0 Then
				Locate 15,Arrow
				Print "  "
				If Arrow=1 Then 
					Arrow=3
				Elseif Arrow=3 Then 
					Arrow=1
				End If
				PrintArrow
			Elseif AlarmPosition=1 Then
				Incr AlarmHr
				Locate 0,2
				Print Dp(AlarmHr,2,1)
			Elseif AlarmPosition=2 Then
				Incr AlarmMin
				Locate 3,2
				Print Dp(AlarmMin,2,1)
				
			Elseif TimePosition=1 Then
				Incr hr
				Timeset 12,hr
				PrintTime 1
			Elseif TimePosition=2 Then
				Incr min
				Timeset 11,min
				PrintTime 1
				
			End If
		End If
			
	
		
	Elseif In(11)=0 Then
		Debug "11!",Cr
		MaxBEEP
		Delay 100

		If MenuMode=0 Then
			If Arrow=1 Then
				Incr SoundMode
				If SoundMode=4 Then SoundMode=0
			'If Arrow at Sleep
			Elseif Arrow=2 Then
				Cls
				Csroff
				PrintTime 1
				Locate 0,1
				Print Dec SleepTime/60
				Arrow=1
				PrintArrow
				
				MenuMode=1
			Elseif Arrow=3 Then
				Cls
				Csroff
				PrintTime 1
				Locate 0,2
				Print Dp(AlarmHr,2,1),":",Dp(AlarmMin,2,1),":00"
				Locate 0,1
				Print "Set Time"
				Locate 0,3
				Print "Set Alarm"
				'Set MenuMode to Alarm and Time setting
				MenuMode=3	
				Arrow=1	
				PrintArrow
				
			End If
		Elseif MenuMode=1 Then
 			If Arrow=1 Then
			   Locate 0,1
				Print "        "
				Locate 0,1
				SleepTime=SleepTime+60
				Print Dec SleepTime/60
				
			End If
   	Elseif MenuMode=3 Then
			If Arrow=3 Then
				Incr AlarmPosition
				If AlarmPosition=1 Then
					Locate 0,3
					Print "                   "
					Locate 0,3
					Print "||"
				Elseif AlarmPosition=2 Then
					Locate 0,3
					Print "  "
					Locate 3,3
					Print "||"
				Elseif AlarmPosition=3 Then
					AlarmPosition=0
					MenuMode=0
					MainMenu
				End If
			Elseif Arrow=1 Then
				Incr TimePosition
				If TimePosition=1 Then
					Locate 0,1
					Print "                   "
					Locate 0,1
					Print "||"
				Elseif TimePosition=2 Then
					Locate 0,1
					Print "  "
					Locate 3,1
					Print "||"
				Elseif TimePosition=3 Then
					TimePosition=0
					MenuMode=0
					MainMenu
				End If			
			End If
		End If
		
	End If
	'Display current time only if seconds has changed
	
	
	
	
	
Return

Do

If status1=0 And ct<255 Or ct<50Then
   status1=0
	Incr ct
Else
   status1=1
	Decr ct
End If

If status2=0 And ct2<255 Or ct2<50 Then
	status2=0
	Incr ct2
Else
	status2=1
	Decr ct2
End If

If status3=0 And ct3<255 Or ct3<50 Then
   status3=0
	Incr ct3
Else 
	status3=1
	Decr ct3
End If


Red ct
Blue ct2
Green ct3




Loop


End

Sub MainMenu()
		Cls
		  Csroff
		PrintTime 1
		Locate 0,1
		Print "Mode"
		Locate 0,2
		Print "Sleep"
		Locate 0,3
		Print "Set Alarm/Time"
		
		Locate 15,Arrow
		Print "<-"
End Sub

Sub PrintArrow()
	Locate 15,Arrow
	Print "<-"
End Sub
		
Sub PrintTime(pmode As Byte)
	sec=Time(10)
	min=Time(11)
	hr=Time(12)
	If hr=24 Then 
		Timeset 12,0
		hr=0
	End If
	
	If pmode=0 Then
		
		If hr<>hr2 Then
			Locate 0,0
			Print Dp(hr,2,1), ":"
		Elseif min <> min2 Then
			Locate 3,0
			Print Dp(min,2,1), ":"
		Elseif sec2 <> sec Then
			If Sleep=1 Then
				If SleepTime=0 Then 
					Sleep=0
					SoundMode=0
				End If
				If SleepTime>0 Then Decr SleepTime
			End If 
			Locate 6,0
			Print Dp(sec,2,1)
		End If
	
	Else 
		Locate 0,0
		Print Dp(hr,2,1), ":",Dp(min,2,1), ":",Dp(sec,2,1)
	End If
	hr2=hr
	min2=min
	sec2=sec
	
End Sub



Sub Blue(DutyValue As Integer)
	'Debug "Blue DutyValue: ",  Dec DutyValue,Cr
	Pwm 0,DutyValue,PeriodL
End Sub

Sub Green(DutyValue As Integer)
	'Debug "Green DutyValue: ",  Dec DutyValue,Cr
	Pwm 1,DutyValue,PeriodL
	
End Sub

Sub Red(DutyValue As Integer)
'	Debug "Red DutyValue: ",  Dec DutyValue,Cr
	Pwm 2,DutyValue,PeriodL
	
End Sub


Sub RGB()
For ct=0 To 1024
	Red ct
Next
For ct=1024 To 1 Step -1
	Red ct
Next

For ct=0 To 1024
	Blue ct
Next
For ct=1024 To 1 Step -1
	Blue ct
Next


For ct=0 To 1024
	Green ct
Next
For ct=1024 To 1 Step -1
	Green ct
Next
End Sub

Sub Alarm(mode As Byte)

Select Case mode
	Case 0
	Green 0
	Blue 255

	Case 1
	Blue 0
   Red 255
	
	Case 2
	Red 0
	Green 255
	
	Case 3
	Blue 255
	Red 255
	Green 0

	Case 4
	Green 255
	Red 255
	Blue 0

   Case 5
	Green 255
	Blue 255
	Red 0

End Select

End Sub


Sub Slow()


For ct=0 To 255
	Blue ct
	Wait sdelay
	If SoundMode=0 Then Exit For
Next


For ct=0 To 255
	Red ct
	Wait sdelay
	If SoundMode=0 Then Exit For
Next

For ct=255 To 10 Step -1
	Blue ct
	Wait sdelay
	If SoundMode=0 Then Exit For
Next


For ct=0 To 255
	Green ct
	Wait sdelay
	If SoundMode=0 Then Exit For
Next

For ct=255 To 10 Step -1
   Red ct
	Wait sdelay
	If SoundMode=0 Then Exit For
Next

For ct=0 To 255
	Blue ct
	Wait sdelay
	If SoundMode=0 Then Exit For
Next
For ct=0 To 255
	Red ct
	Wait sdelay
	If SoundMode=0 Then Exit For
Next

For ct=255 To 10 Step -1
	Blue ct
	Wait sdelay
	If SoundMode=0 Then Exit For
Next

For ct=255 To 10 Step -1
	Red ct
	Wait sdelay
	If SoundMode=0 Then Exit For
Next

For ct=255 To 10 Step -1
	Green ct
	Delay sdelay
	If SoundMode=0 Then Exit For
Next


End Sub


'Parse music notes and play them on piezo

Sub PlayString(PlayNotes As String * 100)
Dim a As Byte
Dim k As Integer
Dim CurrentOctave As Byte


CurrentOctave=0

a=0

	k=PlayNotes_A(0)

	
	Do Until k=33
		If SoundMode <> 1 Then Exit Do
		
		If(k=111 Or k=79) Then			'if O or o for octave Change
			Incr a
			k=PlayNotes_A(a)
			Debug "OCTAVE CHANGED TO: ", k, Cr
			k=k-48
			CurrentOctave=k

		Elseif(k=67 Or k=99) Then			'if C
			Debug k
			Incr a
			k=PlayNotes_A(a)
			If(k=35) Then	'#
				Debug "#"
				Incr a
				k=PlayNotes_A(a)

				If(k>=48 And k<=57) Then		' Between 0 and 9
					Debug k
					k= k-48
					PlayNote 1, k * DELAYTIME,CurrentOctave
				End If
			Elseif (k>=48 And k<=57) Then	' if k between 0 and 9
					Debug k
					k= k-48
					PlayNote 0, k* DELAYTIME, CurrentOctave
			End If

		Elseif(k=68 Or k=100) Then
			Debug "D"
			Incr a
			k=PlayNotes_A(a)

			If(k=35) Then	'#
				Debug "#"
				Incr a
				k=PlayNotes_A(a)

				If(k>=48 And k<=57) Then		' Between 0 and 9
					Debug k
					k=k-48
					PlayNote 3, k * DELAYTIME,CurrentOctave
				End If
			Elseif (k>=48 And k<=57) Then	' if k between 0 and 9
				Debug k
				k= k-48
				PlayNote 2, k* DELAYTIME, CurrentOctave
			End If

		Elseif(k=69 Or k=101) Then
			Debug "E"
			Incr a
			k=PlayNotes_A(a)

				If(k>=48 And k<=57) Then		' Between 0 and 9
					Debug k
					k= k-48
					PlayNote 4, k * DELAYTIME,CurrentOctave
				End If

			End If

		Elseif(k=70 Or k=102) Then
			Debug "F"
			Incr a
			k=PlayNotes_A(a)

			If(k=35) Then	'# 
				Debug "#"
				Incr a
				k=PlayNotes_A(a)

				If(k>=48 And k<=57) Then		' Between 0 and 9
					Debug k
					k=k-48
					PlayNote 6, k * DELAYTIME,CurrentOctave
				End If
			Elseif (k>=48 And k<=57) Then	' if k between 0 and 9
				Debug k
				k= k-48
				PlayNote 5, k* DELAYTIME, CurrentOctave
			End If

		
		Elseif(k=71 Or k=103) Then
			Debug "G"
			Incr a
			k=PlayNotes_A(a)

			If(k=35) Then	'#
				Debug "#"
				Incr a
				k=PlayNotes_A(a)
				
				If(k>=48 And k<=57) Then		' Between 0 and 9
					Debug k
					k=k-48
					PlayNote 8, k * DELAYTIME,CurrentOctave
				End If
			Elseif (k>=48 And k<=57) Then	' if k between 0 and 9
				Debug k
				k= k-48
				PlayNote 7, k* DELAYTIME, CurrentOctave
			End If
		Elseif(k=65 Or k=97) Then
			Debug "A"
			Incr a
			k=PlayNotes_A(a)

			If(k=35) Then	'#
				Debug "#"
				Incr a
				k=PlayNotes_A(a)
				
				If(k>=48 And k<=57) Then		' Between 0 and 9
					Debug k
					k=k-48
					PlayNote 10, k * DELAYTIME,CurrentOctave
				End If
			Elseif (k>=48 And k<=57) Then	' if k between 0 and 9
				Debug k
				k= k-48
				PlayNote 9, k* DELAYTIME, CurrentOctave
			End If

		Elseif(k=66 Or k=98) Then
			Debug "B"
			Incr a
			k=PlayNotes_A(a)

			If (k>=48 And k<=57) Then	' if k between 0 and 9
				Debug k
				k= k-48
				PlayNote 11, k* DELAYTIME, CurrentOctave
			End If
		
		End If
		Incr a
		k=PlayNotes_A(a)
				
		If k=44 Then 'For commas
			Incr a
			k=PlayNotes_A(a)
		End If

	Loop

End Sub

Sub PlayNote(ThisNote As Byte,PlayTime As Integer, Octave As Byte)
Dim tsingle As Single
Dim period As Integer
Dim multiply As Byte


tsingle=NOTES(ThisNote)
Debug " Octave: ", Dec Octave
If Octave>0 Then
	For multiply=1 To Octave 
		tsingle=tsingle * 2
	Next
End If

Debug " Freq: ", Float tsingle
period =GetWidth(tsingle)
Debug " Period: ", Dec period,Cr

'----
Incr AlarmColor
If AlarmColor>5 Then AlarmColor=0
Alarm AlarmColor
'---

Pwm 3,period/2,period

Delay PlayTime
Pwmoff 3

End Sub




'Find (Width)Period of Frequency!

Function GetWidth(Frequency As Single) As Integer
Dim a As Single

a=4/(0.000001*1.735*Frequency)
a=a-1
GetWidth=Floor(a)

End Function



Sub RunBluesRandom()

Dim tsingle As Single					' Max's BLUES Solo!!!
Dim Period As Integer 
Dim bluesrand As Byte
num=Rnd(3) mod 6						'Get random values by using rnd()

Debug Dec num,Cr
tsingle=BLUES(num)

bluesrand=Rnd(0)
Debug "RANDDDD: ",Dec bluesrand,Cr

  If bluesrand <150 Then
	tsingle=tsingle * 16
Else
	tsingle=tsingle * 32
End If
Period=GetWidth(tsingle)
Debug "Result: ",Dec Period,Cr,Cr
'----
Incr AlarmColor
If AlarmColor>5 Then AlarmColor=0
Alarm AlarmColor
'---

Pwm 3,(Period/2),Period

If Rnd(0) <8000 Then	
	Delay 400
Else
	Delay 200
End If

End Sub

'Cool BEEP noise function for PWM3 Piezo
Sub MaxBEEP()
	Pwmoff 3 			'Turn off PWM3
	Dim SJ As Byte
	For SJ = 0 To 50
		Reverse 19
		Udelay 70
		Reverse 19		
	Next
	For SJ = 0 To 80
		Reverse 19
		Udelay 40
		Reverse 19		
	Next
End Sub

Image:Example.jpg

Personal tools