| View previous topic :: View next topic |
| Author |
Message |
Hugolain
Joined: 23 May 2005 Posts: 16
|
Posted: Sat Oct 22, 2005 1:14 am Post subject: Code convert vb6 help |
|
|
Hello,
I use this Function to convert the codes of the type: $80, $AB, $C2 ...
| Code: | Private Sub CcBtnConvert_Click()
CcTxtIRCode.Text = ByteToIRCode(Val("&H" & CcTxtHexa.Text))
End Sub
Public Function ByteToIRCode(ByVal vInput As Byte) As String
Const Header As String = "R08008104"
Const Bit0 As String = "2121"
Const Bit1 As String = "808221"
Do Until vInput = 0
If vInput Mod 2 = 1 Then
ByteToIRCode = ByteToIRCode & Bit1
Else
ByteToIRCode = ByteToIRCode & Bit0
End If
vInput = vInput \ 2
Loop
ByteToIRCode = Header & ByteToIRCode
End Function |
Can one help me has to adapt my Function for the codes of the type: $300+DIR ,$3AA ,$3F0 ...please?
Cordially
Hugolain
PS: | Quote: | The IR Carrier is 39.2kHz. Data is modulated using a space coded signal with 12 data bits (data clock is 1200Hz, but actual data rate varies depending on the data).
For modulating the signals yourself, the signal looks something like this:
Timing based on 1/1200 second clock (~.833ms)
Signal is normally high (idle, no IR).
Start: signal goes low for 8/1200 sec.
Data bits: for each of 12 data bits, space encoded signal depending on bit value
Sends the most significant data bit first
If the data bit is 0: signal goes high for 1/1200 sec, and low for 1/1200 sec.
If the data bit is 1: signal goes high for 4/1200 sec, and low for 1/1200 sec.
BTW: the first 4 bits are always "0011" for the Robosapien V2
When completed, signal goes high again.
No explicit stop bit. Minimal between signals is not known.
|
|
|
| Back to top |
|
 |
Hugolain
Joined: 23 May 2005 Posts: 16
|
Posted: Mon Oct 24, 2005 6:50 pm Post subject: |
|
|
Is that it correct?
Private Sub CcBtnConvert_Click()
CcTxtIRCode.Text = ByteToIRCode(Val("&H" & CcTxtHexa.Text))
End Sub
Public Function ByteToIRCode(ByVal vInput As Integer) As String
Const Header As String = "R08008104"
Const Bit0 As String = "2121"
Const Bit1 As String = "808221"
Do Until vInput = 0
If vInput Mod 2 = 1 Then
ByteToIRCode = ByteToIRCode & Bit1
Else
ByteToIRCode = ByteToIRCode & Bit0
End If
vInput = vInput \ 2
Loop
ByteToIRCode = Header & ByteToIRCode
End Function
Private Sub Form_Load()
End Sub |
|
| Back to top |
|
 |
Hugolain
Joined: 23 May 2005 Posts: 16
|
Posted: Tue Oct 25, 2005 8:37 pm Post subject: |
|
|
Small error!
replace:
| Code: | If vInput Mod 2 = 1 Then
ByteToIRCode = ByteToIRCode & Bit1
Else
ByteToIRCode = ByteToIRCode & Bit0
End If |
by:
| Code: | If vInput Mod 2 = 1 Then
ByteToIRCode = Bit1 & ByteToIRCode
Else
ByteToIRCode = Bit0 & ByteToIRCode
End If |
|
|
| Back to top |
|
 |
Hugolain
Joined: 23 May 2005 Posts: 16
|
Posted: Thu Oct 27, 2005 9:34 am Post subject: |
|
|
appreciate your help please !!
hugolain |
|
| Back to top |
|
 |
jrhees Site Admin
Joined: 28 Jan 2003 Posts: 1652
|
Posted: Thu Oct 27, 2005 3:35 pm Post subject: |
|
|
You have another error -- you'll need the loop to execute 12 times (once for each bit) -- whereas currently the way your code is written, the loop will only repeat 10 times (since no IR code appears to have bits 10 or 11 set to '1'.
-Jon |
|
| Back to top |
|
 |
Hugolain
Joined: 23 May 2005 Posts: 16
|
Posted: Thu Oct 27, 2005 8:16 pm Post subject: |
|
|
Is that it correct?
| Code: | Private Sub CcBtnConvert_Click()
CcTxtIRCode.Text = ByteToIRCode(Val("&H" & CcTxtHexa.Text),12)
End Sub |
| Code: | Public Function ByteToIRCode(ByVal vInput As Integer, Optional ByVal vNbBits As Integer = 8) As String
Const Header As String = "R08008104"
Const Bit0 As String = "2121"
Const Bit1 As String = "808221"
Do Until vNbBits <= 0
If vInput Mod 2 = 1 Then
ByteToIRCode = Bit1 & ByteToIRCode
Else
ByteToIRCode = Bit0 & ByteToIRCode
End If
vInput = vInput \ 2
vNbBits = vNbBits - 1
Loop
ByteToIRCode = Header & ByteToIRCode
End Function |
|
|
| Back to top |
|
 |
jrhees Site Admin
Joined: 28 Jan 2003 Posts: 1652
|
Posted: Fri Oct 28, 2005 12:37 am Post subject: |
|
|
I think so...?
-Jon |
|
| Back to top |
|
 |
|