I thought this would be trivial but apparently not. I've simplified this to just be a single output for now.
Dim Start As UInteger = 0 Dim [End] As UInteger = 255 Dim Steps = 100 For x = 1 To Steps Dim Temp = ([End] - Start) / Steps * x + Start Dim R = CUInt(Temp) Debug.Print(x.ToString & ": Temp: " & Temp.ToString & ", R:" & R.ToString) LedR.SetPulse(255, R) Threading.Thread.Sleep(20) Next
1: Temp: 2.5500, R:196608 2: Temp: 5.1000, R:327680 3: Temp: 7.6500, R:524288 4: Temp: 10.2000, R:655360 5: Temp: 12.7499, R:851968 ... 95: Temp: 242.2488, R:15859712 96: Temp: 244.7988, R:16056320 97: Temp: 247.3488, R:16187392 98: Temp: 249.8988, R:16384000 99: Temp: 252.4488, R:16515072 100: Temp: 254.9988, R:16711680
As you can see the actual calculation works perfectly but I can't find ANY way to shoe-horn the resulting double into a UInt.
NB: In this scenario, I don't care at all about precision so Ceil/Floor/Truncate are all perfectly acceptable.
Dim R = CUInt(Temp) 'Odd output - maybe reading memory and just treating it as a UInt Dim R = CType(Temp, UInteger) 'Throws: An unhandled exception of type 'System.Exception' occurred in Netduino_VBTest.exe Dim R = Convert.ToUInteger(Temp) 'Doesn't have an overload for Double (or anything except string!) Dim R = Convert.ToUInteger(Temp.ToString) 'Throws an exception
Any suggestions appreciated.