|
Forum Index : Microcontroller and PC projects : HC-12
| Author | Message | ||||
| CaptainBoing Guru Joined: 07/09/2016 Location: United KingdomPosts: 2171 |
+1 true dat |
||||
| macca Newbie Joined: 21/02/2017 Location: AustraliaPosts: 32 |
Hi to all again Still have problems but this time with DHT12 can not get the led to come on when temp is higher than numberbox. eg code below 'E100 board 'Firmware V5.04.09 cls Const frm_alarm = 1, nbr_hi = 2, nbr_lo = 3 Const c_hi = 4, c_lo = 5, tempa = 6, huma = 7, led_alarm = 8 const hi_alarm = 9 DIM float Temp, hum humid 28, Temp, Hum Font 3 : GUI Frame frm_alarm, "Alarm", 380, 150, 200, 130,RGB(green) GUI Caption c_hi, "High:", 390, 170, "LT", RGB(yellow) GUI Numberbox nbr_hi, 470,MM.VPos-6,90,MM.FontHeight+12,RGB(yellow),RGB(64,64,64) GUI Caption c_lo, "Low:", 390, 220, LT, RGB(yellow),0 GUI Numberbox nbr_lo, 470,MM.VPos-6,90,MM.FontHeight+12,RGB(yellow),RGB(64,64,64) font 2 GUI Displaybox tempa,125,122,55,40,RGB(green),RGB(red) GUI Displaybox huma,125,170,55,40,RGB(green),RGB(red) GUI LED led_alarm, "Alarm", 250, 300, 45, rgb(red) GUI Caption hi_alarm, "High:", 30, 130, "LT", RGB(yellow) CtrlVal(led_alarm) = 0 do pause 2000 if CtrlVal(tempa) > nbr_hi then 'problem is here I think ?? CtrlVal(led_alarm) = 1 'led stays on regardles if tempa or nbr_hi is low or high ?? CtrlVal(tempa) = str$(Temp)'temp from DHT12 CtrlVal(huma) = str$(Hum) 'Humidity from DHT12 endif loop CSub HUMID integer, float, float 0000002B 27BDFFF8 AFBF0004 00852023 03E42021 ACC40000 8FBF0004 03E00008 27BD0008 27BDFFE0 AFBF001C 00002021 3C059D00 24A50040 27A60010 0411FFF1 00000000 8FA30010 3C029D00 8C4200BC 3C049D00 24840414 0040F809 00832021 8FBF001C 03E00008 27BD0020 00041080 000419C0 00621823 00642021 000418C0 3C029D00 8C420000 3C047735 34849400 8C420000 0082001B 004001F4 00002012 0064001B 008001F4 03E00008 00001012 27BDFFB8 AFBF0044 AFBE0040 AFB7003C AFB60038 AFB50034 AFB40030 AFB3002C AFB20028 AFB10024 AFB00020 00808821 00A0A821 3C029D00 8C420000 8C430000 3C020098 34429680 0062102B 10400003 00C0B021 0411FFC7 00000000 3C109D00 8E02001C 8E240000 0040F809 24050006 8E020010 8E240000 24050009 0040F809 00003021 8E02001C 8E240000 0040F809 2405000E 8E02001C 8E240000 0040F809 24050005 8E020004 0040F809 240403E8 8E02001C 8E240000 0040F809 24050006 8E020080 240403E8 0040F809 00002821 AEC20000 AEA20000 0411FFB8 24040190 00409821 0000A021 40944800 00008021 10000005 3C129D00 40104800 0270102B 1440008E 8FBF0044 8E420020 0040F809 8E240000 1440FFF8 00000000 10000007 3C129D00 40104800 0270102B 50400004 8E420020 10000081 8FBF0044 8E420020 0040F809 8E240000 1040FFF6 00000000 10000007 3C129D00 40104800 0270102B 50400004 8E420020 10000074 8FBF0044 8E420020 0040F809 8E240000 1440FFF6 00001021 00001821 AFA20010 AFA30014 0000B821 10000005 3C129D00 40104800 0270102B 14400065 8FBF0044 8E420020 0040F809 8E240000 1040FFF8 00000000 40944800 10000006 8E420020 40104800 0270102B 14400059 8FBF0044 8E420020 0040F809 8E240000 1440FFF8 8FA30010 000317C2 8FA50014 0005F040 005EF025 00031040 AFA20018 0411FF6C 24040032 0050102B 8FA30018 00431025 AFA20010 26F70001 24050028 16E5FFE0 AFBE0014 001E1600 8FA50010 00052202 00442025 001E1200 00058E02 00518825 7CA33C00 308200FF 00621821 322200FF 00621821 93A50014 30A200FF 00621021 8FA30010 00431026 304200FF 1440002F 001EA603 3C109D00 8E130064 8E020080 30847FFF 0040F809 00002821 00409021 8E020080 2404000A 0040F809 00002821 02402021 0260F809 00402821 00408021 AEA20000 3C020080 8FA50010 00451024 5040000C 3C109D00 3C029D00 8C520058 8C420080 2404FFFF 0040F809 2405FFFF 02002021 0240F809 00402821 AEA20000 3C109D00 8E120064 8E020080 02202021 0040F809 02802821 00408821 8E020080 2404000A 0040F809 00002821 02202021 0240F809 00402821 AEC20000 8FBF0044 8FBE0040 8FB7003C 8FB60038 8FB50034 8FB40030 8FB3002C 8FB20028 8FB10024 8FB00020 03E00008 27BD0048 20555043 65657073 6F742064 6F6C206F 000A0D77 End CSub ' End program. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' I am doing something wrong but cannot put my finger on it Regards John |
||||
| Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3308 |
I might be reading your program incorrectly but in your do loop you only ever set CtrlVal(led_alarm) high (never low). This is why it stays on. Geoff Graham - http://geoffg.net |
||||
| macca Newbie Joined: 21/02/2017 Location: AustraliaPosts: 32 |
Hi Geoffg Below is program with errors, I cannot get this working 'E100 board 'Firmware V5.04.09 cls Const frm_alarm = 1, nbr_hi = 2, nbr_lo = 3 Const c_hi = 4, c_lo = 5, tempa = 6, huma = 7, led_alarm = 8 const hi_alarm = 9 DIM float Temp, hum 'humid 28, Temp, Hum Font 3 : GUI Frame frm_alarm, "Alarm", 380, 150, 200, 130,RGB(green) GUI Caption c_hi, "High:", 390, 170, "LT", RGB(yellow) GUI Numberbox nbr_hi, 470,MM.VPos-6,90,MM.FontHeight+12,RGB(yellow),RGB(64,64,64) font 2 GUI Displaybox tempa,125,122,55,40,RGB(green),RGB(red) GUI Displaybox huma,125,170,55,40,RGB(green),RGB(red) GUI LED led_alarm, "Alarm", 250, 300, 45, rgb(red) GUI Caption hi_alarm, "High:", 30, 130, "LT", RGB(yellow) CtrlVal(led_alarm) = 0 A = 0 Temp = 28 do CtrlVal(tempa) = str$(Temp)'temp from DHT12 'CtrlVal(huma) = str$(Hum) 'Humidity from DHT12 text 10, 10, str$(Temp) print CtrlVal(nbr_hi) ' this prints 0 as it should text 100, 10, str$(nbr_hi) ' this prints 2 ?????????? 'text 130, 10,CtrlVal(nbr_hi) 'Error: Expected a string 'text 130, 10,CtrlVal(str$(nbr_hi)) 'Error: Expected a number if str$(Temp) > CtrlVal(nbr_hi) then 'Error: Incompatible types in expression '> ?VAL Temp: ?VAL nbr_hi ' 0 28 '0 2 CtrlVal(led_alarm) = 1 elseif str$(Temp) < str$(nbr_hi) then pause 3000 CtrlVal(led_alarm) = 0 else endif pause 1000 A = A + 1' Counting loops text 10, 310, str$(A) loop CSub HUMID integer, float, float 0000002B 27BDFFF8 AFBF0004 00852023 03E42021 ACC40000 8FBF0004 03E00008 27BD0008 27BDFFE0 AFBF001C 00002021 3C059D00 24A50040 27A60010 0411FFF1 00000000 8FA30010 3C029D00 8C4200BC 3C049D00 24840414 0040F809 00832021 8FBF001C 03E00008 27BD0020 00041080 000419C0 00621823 00642021 000418C0 3C029D00 8C420000 3C047735 34849400 8C420000 0082001B 004001F4 00002012 0064001B 008001F4 03E00008 00001012 27BDFFB8 AFBF0044 AFBE0040 AFB7003C AFB60038 AFB50034 AFB40030 AFB3002C AFB20028 AFB10024 AFB00020 00808821 00A0A821 3C029D00 8C420000 8C430000 3C020098 34429680 0062102B 10400003 00C0B021 0411FFC7 00000000 3C109D00 8E02001C 8E240000 0040F809 24050006 8E020010 8E240000 24050009 0040F809 00003021 8E02001C 8E240000 0040F809 2405000E 8E02001C 8E240000 0040F809 24050005 8E020004 0040F809 240403E8 8E02001C 8E240000 0040F809 24050006 8E020080 240403E8 0040F809 00002821 AEC20000 AEA20000 0411FFB8 24040190 00409821 0000A021 40944800 00008021 10000005 3C129D00 40104800 0270102B 1440008E 8FBF0044 8E420020 0040F809 8E240000 1440FFF8 00000000 10000007 3C129D00 40104800 0270102B 50400004 8E420020 10000081 8FBF0044 8E420020 0040F809 8E240000 1040FFF6 00000000 10000007 3C129D00 40104800 0270102B 50400004 8E420020 10000074 8FBF0044 8E420020 0040F809 8E240000 1440FFF6 00001021 00001821 AFA20010 AFA30014 0000B821 10000005 3C129D00 40104800 0270102B 14400065 8FBF0044 8E420020 0040F809 8E240000 1040FFF8 00000000 40944800 10000006 8E420020 40104800 0270102B 14400059 8FBF0044 8E420020 0040F809 8E240000 1440FFF8 8FA30010 000317C2 8FA50014 0005F040 005EF025 00031040 AFA20018 0411FF6C 24040032 0050102B 8FA30018 00431025 AFA20010 26F70001 24050028 16E5FFE0 AFBE0014 001E1600 8FA50010 00052202 00442025 001E1200 00058E02 00518825 7CA33C00 308200FF 00621821 322200FF 00621821 93A50014 30A200FF 00621021 8FA30010 00431026 304200FF 1440002F 001EA603 3C109D00 8E130064 8E020080 30847FFF 0040F809 00002821 00409021 8E020080 2404000A 0040F809 00002821 02402021 0260F809 00402821 00408021 AEA20000 3C020080 8FA50010 00451024 5040000C 3C109D00 3C029D00 8C520058 8C420080 2404FFFF 0040F809 2405FFFF 02002021 0240F809 00402821 AEA20000 3C109D00 8E120064 8E020080 02202021 0040F809 02802821 00408821 8E020080 2404000A 0040F809 00002821 02202021 0240F809 00402821 AEC20000 8FBF0044 8FBE0040 8FB7003C 8FB60038 8FB50034 8FB40030 8FB3002C 8FB20028 8FB10024 8FB00020 03E00008 27BD0048 20555043 65657073 6F742064 6F6C206F 000A0D77 End CSub ' End program. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Sorry to be a pain in the bum I have tried different ways and the same problem pops up Probably I have missed something Best regards John |
||||
| Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3308 |
Good grief! I don't know where to start. There are so many misunderstandings in your code that I can only give some general pointers. The first thing that you should do is use the code button to insert your code in your posts. That will retain any indenting which is essential to understanding someone else's code. This is just a few comments that are obvious: text 100, 10, str$(nbr_hi) ' this prints 2 ?????????? Of course it will print 2... this is what you set nbr_hi to. text 130, 10,CtrlVal(nbr_hi) 'Error: Expected a string CtrlVal(nbr_hi) refers to a NUMBERBOX which returns a float number. TEXT expects a string. That is why you got an error. text 130, 10,CtrlVal(str$(nbr_hi)) 'Error: Expected a number What are you trying to do here? CtrlVal() expects a number as an argument and you are giving it a string! if str$(Temp) > CtrlVal(nbr_hi) then 'Error: Incompatible types in expression You are trying to compare a string with a number. You may not realise that CtrlVal() can return a string or a number depending on the control you are querying. For example using CtrlVal() on a TEXTBOX will return a string (because it holds a string) and on a NUMBERBOX it will return a number (because that is what a number box will hold). My advice is: - Read the sections dealing with data types and GUI controls in Getting Started with the Micromite and both manuals (Micromite User Manual and Micromite Plus Manual) in detail - I know, that is a lot of reading but you seem to be stabbing in the dark without knowing what is in the manuals. - Break your program down into small bits and test and understand each bit before trying the next. For example, just have a NUMBERBOX (nothing else) and experiment with getting its value and doing things with its value. Then try a TEXTBOX, LED, etc. When you know how each works you can put them together and they should do their job without any surprises. Trying for a quick route to the final solution inevitably leads to catastrophe. Geoff Geoff Graham - http://geoffg.net |
||||
| macca Newbie Joined: 21/02/2017 Location: AustraliaPosts: 32 |
sorry for this I will read and not bother the forum again. some people have the gift and some don't. regards to you and the rest. |
||||
| matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 10572 |
Please don't get put off from posting if you need help. However, as Geoff says you are really getting into the most complex area of the Micromite and need a bit more background. The key thing to understand is there are three datatypes supported by MMBasic Strings Integers Floating Point numbers You can combine integers and floats in various expressions but it critical you understand what you are trying to achieve in doing so Strings and numbers can't be combined but can be converted VAL converts a string to a number STR$ converts a number to a string For best programming practice always start your code with OPTION EXPLICIT OPTION DEFAULT NONE This will force you to declare and type all your variables and makes errors much less likely (albeit at the expense of a bit more effort up front). The CTRLVAL function is a special case and can return either a string or a number depending on the GUI control with which it is associated. There is no way round this one for any of us except checking the manual. |
||||
Grogster![]() Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9753 |
Please don't mis-read Geoff's post above. He is just trying a bit of 'tough-love' on you, to try to get you to go to the manuals, as that is what they were written for, and pretty much 99% of all your issues can be solved by reading the manuals. ![]() You are NOT bothering the forums. As you say, some people can pick this stuff up in one pass, but others have more of an issue understanding the logic of how commands work. That is not anything to be ashamed of. Keep on tinkering, and posting your codes that DON'T work. Use the CODE HTML tags as Geoff suggested. Click the 'code' button just above this text-entry box, just below the 'Size' drop-down menu thing-y, and paste your code in between the two markers that the forum software will plop there for you. ![]() I had similar problems when I started using the GUI controls, so you are not the only one to have issues. Most of us have crashed and burned in the beginning as we teach ourselves how to use the GUI controls. ![]() I know EXACTLY the feeling you are having with your CtrlVal issues. As Geoff and matherp point out, CtrlVal's are a unique beast in MMBASIC, and can be different types, and you simply CAN'T make the assumption that a certain control will be a string or a number. You have to be sure of that FIRST, and then make conversions from one to the other with VAL and STR$ as matherp points out. Don't despair - we are here to help you, so you keep on doing what you're doing. Smoke makes things work. When the smoke gets out, it stops! |
||||
| Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3308 |
Sorry for coming across as critical macca. What I was trying to say is that it was not possible to simply correct your code. The solution to getting your program running was for you to understand data types and the manuals are a good place for that. Understanding a concept in programming can often be like turning on a light - all of a sudden it is much easier to see and understand. So don't give up. Geoff Graham - http://geoffg.net |
||||
Quazee137![]() Guru Joined: 07/08/2016 Location: United StatesPosts: 600 |
@macca Please keep learning and then posting here. This has been the best forum on coding and hardware I have been lucky to have found. All the members here share and help. As for helping sometimes pointing us to READ THEN MANUAL is far more helpful than giving a fix we may not understand. Then when we have better knowledge of MMBasic they give even more by being the best sounding board for ideas/code/hardware you could want! My Thanks to all here at TBS Quazee |
||||
bigmik![]() Guru Joined: 20/06/2011 Location: AustraliaPosts: 2971 |
Hi Macca, Don’t despair we are not all good at programming.. God knows I am next to useless. Although I get by generally. What I do is try small sections of code to see what various commands return.. The best ocean swimmers started by paddling in kiddie pools... you really can’t expect a lengthy piece of code to work straight off .. Even Geoff and Peter, who are amongst the best, if not the best, at coding are still fixing bugs in code they thought were fine when released.. One problem I personally have is misunderstanding what a command means and every time I proof read my code I assume that a command does what I want (not what I told it to) Try putting print lines before and after a suspect line to print the relevant variables before the code and again after.. add pauses if needed.. this way you can determine if the section of code returns what you thought it would. Keep on trying you will get there one day.. it is part of the fun and satisfaction at getting a working project. Regards, Mick Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<< |
||||
| macca Newbie Joined: 21/02/2017 Location: AustraliaPosts: 32 |
Hi and thankyou to Geoff, Grogster, matherp for your encouraging information and thoughts, I will be printing the manuals out as I find trying to read the manuals of the same computer then switching to MMEdit a bit confusing, and yes you are right in what I should be doing "eg. reading the manuals more". I have not giving up just taking a breather and gathering my thoughts. And yes you guy's are the best. Best Regards I'll get there John |
||||
| CaptainBoing Guru Joined: 07/09/2016 Location: United KingdomPosts: 2171 |
Don't be like that forums are designed to be bothered! You should NEVER feel you are "pestering" in a forum if you are genuinely seeking advancement. Anyone who doesn't want to follow a particular thread knows where the close button is. Just about the only skills any of us were born with was screaming and swimming(ish). Keep on posting - God knows I went through some curves during my time here on this rock and it is only by "bothering" others of a like mind (it was computer clubs back then... which deteriorated into copy-fests and punch-ups over Amiga Vs Atari sadly) that I got as far as I have. Trust me, it will suddenly "click" into place. |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |