-2

I don't know enough C and circuit-python mnemonics to convert seconds to 28 year epoch, for rp2040 mcu scripts on WOKWI.

This first code block is my micropython attempt.

I don't know how to declare a 64 bit number and the variable containing the second must go up to 28 years in seconds.

I'm not sure circuit python supports double unsigned integers.

I guess I could just break this down into smaller integers since it's already broken down into smaller integers here. But I'd much rather find something that will support the whole giant number so that I can set the seconds to a basic calendar epoch(28 years)(in case it is off line for 28 years).

I'm trying to do this with internal commands (machine) (no import) just from the basic internal micropython interpreter which is resident in the RP2040.

https://wokwi.com/projects/370990490026911745

sec=604800-10
s=2
def  tickjsj():
  global sec
  sec=sec+1
machine.Timer().init(period=1000, callback=lambda t:tickjsj())
while 1:
  if s!=sec:
    ss=int((sec/60-int(sec/60))*60)
    m=int((sec/3600-int(sec/3600))*60)
    h=int((sec/86400-int(sec/86400))*24)
    d=int((sec/604800-int(sec/604800))*7)
    # 4y=int((sec/126230400-int(sec/126230400)))
    print("d=",d,"sumotuwethfrsa"[d*2:d*2+2],"h="+("0"+str(h))[-2:],"m="+("0"+str(m))[-2:],"s="+("0"+str(ss))[-2:],chr(13),end="")

    s=sec


The second code block below is not fully working C that I Made by modifying a working script modified by the system operator from some other source can't say I don't appreciate the rem statements for the Addafruit driver of the OLED display even though ultimately I intend to use my own brewed of bitbanged serial driven 7 segment LED: https://wokwi.com/projects/372024462517265409

#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
unsigned long  x = 4294967295-100;
unsigned long  sec=0;
unsigned long  ss=0;
unsigned long  m=0;
unsigned long  h=0;
unsigned long  d=0;
void setup() {
  if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Don't proceed, loop forever
  }
  display.setRotation(4); //sets rotation 1 through 4  
  display.display();
  display.setTextColor(1);        // Draw white text
  display.setTextSize(3); 
}
void loop() {
  display.clearDisplay();
  display.setCursor(0,0);
  ss=x;
  ss=int((sec/60-int(sec/60))*60);
  m=int((sec/3600-int(sec/3600))*60);
  h=int((sec/86400-int(sec/86400))*24);
  d=int((sec/604800-int(sec/604800))*7);
  //# 4y=int((sec/126230400-int(sec/126230400)))
  //display.print("d=",d,"sumotuwethfrsa"[d*2:d*2+2],"h="+("0"+str(h))[-2:],"m="+("0"+str(m))[-2:],"s="+("0"+str(ss))[-2:],chr(13),end="");
  display.print("d=");
  display.print(d);
  display.print("h=");
  display.print(h);
  display.print("m=");
  display.print(m);
  display.print("s=");
  display.print(ss);
  display.print(x);
  display.display();
  x++;
}

I don't know the "c" language mnemonics. Therefore the "INT" function translates into some other command or function with "C".

The micropython script won't count high enough. Because I can't get a high enough precision on the numeric value.

Elzaidir
  • 891
  • 6
  • 13
  • 1
    Your text is hard to read. I suggest to [edit] the question, check the spelling and use paragraphs, lists, inline code formatting (by using backticks) etc to make it easier to read and understand. Make clear what's wrong with your code or what problem you want to solve. – Bodo Aug 09 '23 at 10:56
  • You don't have to declare the number of bits in an integer in Python; it supports integers of any size. I believe that's true of MicroPython too, but I haven't tried. Could you clearly explain what your Python code is supposed to do, and show us what output it gives and what output you would expect it to give? What exactly do you mean by "convert seconds to 28 year epoc" and can you give some examples? Also, please use a spell checker and fix your errors. – David Grayson Aug 09 '23 at 17:37
  • oh!!! let me clarify.. when i initialize it like this "a=0" , it will be the compressed low signed integer rage.. - but if you set it to the highest value that you expect the number to go to.. then that will be it's precision. e.g. "a = 999999999999999999999" then "a=a+1" you get 1000000000000000000000 so if i go "seconds=883008000". (i.e. "60*60*24*(((365*4)+1)7)= 883008000"). it should work? - the 999 thing works! I'm sure that i see what your saying.. I've read that but didn't get it. now i do. thank you David Grayson. your amazing – Jonathan James Aug 10 '23 at 02:15
  • I can see that you're saying that you don't have to declare precision with python. But yeah like I said in the previous comment to your reply. Now I see that it's when you assign the variable in the assignation,, whatever you initially assign the variable to,, however the interpreter renders that number.. That's how many bits it's gonna have. But yet after that point,, if you exceed it's initialization precision level,, it will do an overflow. But it won't actually shut the system down,, it just gracefully circulates back to zero. If it's unsigned. – Jonathan James Aug 10 '23 at 03:57

0 Answers0