Shop OBEX P1 Docs P2 Docs Learn Events
Help someone getting back into messing around with propellers.. — Parallax Forums

Help someone getting back into messing around with propellers..

I just got a propeller pro dev board, and am having a bit of fun with it, I tried to use the rtc and the 16 segment led displays to make a clock, but my attempt isnt working properly. instead of printing hours mins and seconds, its only printing the mins twice.. how can I make it easy for others to help me?

also I had a account under the name firehopper, but that was on a lavabit email account. (the lavabit servers shut down a long time ago) so I dont have access to that email account. so I cant reset the password for my old account to get access to it again.. dont know where to go for help for that.

Comments

  • Can we see your code?

    If it's just one file, you can include it in this post in [ code][/code] tags (except the space between "[" and "c" is not actually there, I just put it there to make the forum software not notice it).

    Here's an example of code tags:
    PRI asdf
      return 3
    
  • its a program file, then some files from the sixteensegment demo and the ds1302 full demo do I need to post those as well. and some library/object files used in those demos.
  • What IDE are you using? Can you look around in the menus and find and push an entry that says something like Create Propeller Archive, and upload the resulting .zip file?

    Also, about your old forum account, have you tried emailing Parallax about it?
  • also I had a account under the name firehopper, but that was on a lavabit email account. (the lavabit servers shut down a long time ago) so I dont have access to that email account. so I cant reset the password for my old account to get access to it again.. dont know where to go for help for that.

    About to PM you on this.

  • VonSzarvas wrote: »
    also I had a account under the name firehopper, but that was on a lavabit email account. (the lavabit servers shut down a long time ago) so I dont have access to that email account. so I cant reset the password for my old account to get access to it again.. dont know where to go for help for that.

    About to PM you on this.

    okay


  • this is what I was given for free, so I'm messin around with it :)

    26289511484_006d2307e7_b.jpg
    26860893136_a684f60b3c_b.jpg
  • VonSzarvas wrote: »
    also I had a account under the name firehopper, but that was on a lavabit email account. (the lavabit servers shut down a long time ago) so I dont have access to that email account. so I cant reset the password for my old account to get access to it again.. dont know where to go for help for that.

    About to PM you on this.

    and vons fixed it for me :) yay have my old account back

  • ElectrodudeElectrodude Posts: 1,657
    edited 2016-05-12 05:07
    Your bug is on line 84 of rtcclock.spin.
        time := s.Combine(SN.decx(hour,2),SN.decx(minute,2))
        Send(time)
    

    First, you call SN.decx(hour, 2), which converts hour to a two digit decimal string, puts it in a byte array nstr in Strings.spin, and returns a pointer to that string. Then, you call SN.decx(minute, 2), which overwrites nstr with the minutes. Then, you use s.Combine to concatenate the string that used to contain hours (and now contains minutes) with the string that now contains the minutes. You are concatenating the same string, which contains minutes, to itself.

    One solution is to call SN.decx(hour, 2), bytemove the result into a temporary buffer, call SN.decx(minute, 2), and then s.Combine them. You can use strsize to figure out how many bytes long the hour string is, or you can just know that it's 3 bytes (including the null terminator) and hardcode it.

    However, I wouldn't recommend using a function like s.Combine, since string functions with buffers hidden in objects are a great source of bugs like this. I would just bytemove everything into my own buffer, and pass a pointer to that buffer to Send:
    VAR
    ...
      byte ledstring[15] ' Size of SixteenSegment's buffer, plus 1 for a null terminator
    ...
    PUB main | ...
    ...
    ' line 84
        bytemove(@ledstring[0], SN.decx(hour, 2), 2)
        bytemove(@ledstring[2], SN.decx(minute, 2), 2)
        ledstring[4] := 0 ' append null terminator
        Send(@ledstring)
    

    You could even write a function that takes a pointer to a string, appends it to the end of ledstring, and updates an index to make finding the end of ledstring next time easy.
  • Your bug is on line 84 of rtcclock.spin.
        time := s.Combine(SN.decx(hour,2),SN.decx(minute,2))
        Send(time)
    

    First, you call SN.decx(hour, 2), which converts hour to a two digit decimal string, puts it in a byte array nstr in Strings.spin, and returns a pointer to that string. Then, you call SN.decx(minute, 2), which overwrites nstr with the minutes. Then, you use s.Combine to concatenate the string that used to contain hours (and now contains minutes) with the string that now contains the minutes. You are concatenating the same string, which contains minutes, to itself.

    One solution is to call SN.decx(hour, 2), bytemove the result into a temporary buffer, call SN.decx(minute, 2), and then s.Combine them. You can use strsize to figure out how many bytes long the hour string is, or you can just know that it's 3 bytes (including the null terminator) and hardcode it.

    However, I wouldn't recommend using a function like s.Combine, since string functions with buffers hidden in objects are a great source of bugs like this. I would just bytemove everything into my own buffer, and pass a pointer to that buffer to Send:
    VAR
    ...
      byte ledstring[15] ' Size of SixteenSegment's buffer, plus 1 for a null terminator
    ...
    PUB main | ...
    ...
    ' line 84
        bytemove(@ledstring[0], SN.decx(hour, 2), 2)
        bytemove(@ledstring[2], SN.decx(minute, 2), 2)
        ledstring[4] := 0 ' append null terminator
        Send(@ledstring)
    

    You could even write a function that takes a pointer to a string, appends it to the end of ledstring, and updates an index to make finding the end of ledstring next time easy.

    that worked. and as for pointers. I dont think I'm ready for that :) I did modify your code a tiny bit by adding a bytemove for the seconds and it worked :) thanks so much. :)
Sign In or Register to comment.