Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Peripheral Wrapping
- local solarGenerator=peripheral.wrap("back")
- -- Global Variables
- local Discharging=0
- local count=0
- local oldBat=0
- -- Functions
- function isDaylight()
- return redstone.getAnalogInput("left")
- end
- function checkBattery()
- return ((solarGenerator.getEnergyStored() / solarGenerator.getMaxEnergyStored())*100)
- end
- function Discharge()
- redstone.setAnalogOutput("back",15)
- Discharging=true
- end
- function Charge()
- redstone.setAnalogOutput("back",0)
- Discharging=false
- count=0
- end
- -- Main Loop
- Charge()
- while true do
- if (isDaylight() > 0) then
- if (checkBattery() > 99 and Discharging==false) then
- print("Battery is full. Discharging")
- Discharge()
- end
- else
- print("No daylight detected. Discharging.")
- Discharge()
- end
- print("Waiting... ("..checkBattery().."%)")
- if (checkBattery()<1) then
- print ("Internal battery discharged. Charging")
- Charge()
- end
- if (checkBattery()==oldBat) then
- count=count+1
- else
- oldBat=checkBattery()
- end
- if (count>5) then
- Charge()
- end
- sleep(10)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement