Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal

Mumberthrax

Members
  • Content Count

    2
  • Joined

  • Last visited

Posts posted by Mumberthrax

  1. local rs = component.proxy(component.list("redstone")())
    
    local ceiling = 14      --/15
    local floor = 1
    local intervalSeconds = 10
    local capSide = 4       -- http://ocdoc.cil.li/api:sides
    
    local rsLevel = 0
    local capLevel = 0
    
    
    function sleep(timeout)
      local deadline = computer.uptime() + (timeout or 0)
      repeat
        computer.pullSignal(0)
      until computer.uptime() >= deadline
    end
    
    
    while true do
      capLevel = rs.getComparatorInput(capSide)
      if capLevel >= ceiling then
        rsLevel = 1
      elseif capLevel <= floor then
        rsLevel = 0
      end
      rs.setOutput(capSide, rsLevel)
    -- debug stuff
      rs.setOutput(3, rsLevel)
      rs.setOutput(5, capLevel)
    
      rs.setOutput(2, 1)
      sleep(1)
      rs.setOutput(2, 0)
    -- end debug
      sleep(intervalSeconds)
    end

    Very simple microcontroller program (though as it is my first, it took me a while to figure out how to make it work considering the documentation on microcontrollers is not very good for newbies).

    Measures the comparator level of an adjacent block (I created it to measure the energy stored in an enderIO capacitor), emits a signal back if the comparator signal is full strength, stops emitting if it is at 0 (or any other configured values). This was made to manage an energy storage system, so that our reactor would not be running all the time at low levels, would not be stopping and starting in tiny bursts, but rather would have larger cycles more infrequently.

    https://pastebin.com/NucrVHkm

     

    The lines between the comments about debugging can be safely removed, but I've left them in case they are in any way educational for someone else. I had a lot of trouble finding example code for microcontrollers, so i figured I'd post this one in case it's helpful to someone else. One thing that tripped me up for a little while was figuring out how to make the program sleep for a while since there is no sleep method available in a microcontroller. I had found this page: http://lua-users.org/wiki/SleepFunction, and tried several of the functions there but each gave me some kind of error after a little while. I ended up copying the sleep function from openOS's library files, and modifying it a little bit... I'm using computer.pullSignal() to take up time, though i don't entirely know yet what this function does i do recognize that it stalls for a little bit so it works well enough for my sleep function's needs.

    But yeah, for any newbies who may see this in the future, this page http://ocdoc.cil.li/tutorial:custom_oses and scouring openOS's libraries https://github.com/MightyPirates/OpenComputers/tree/master-MC1.7.10/src/main/resources/assets/opencomputers/loot/openos/boot was what ended up helping, as well as a german video sangar made (though i don't speak german)

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.