This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
darcline's profile picture

Automatic Door

Started by darcline, 27 June 2017 - 09:50 AM
darcline #1
Posted 27 June 2017 - 11:50 AM
Hello World,

at the moment i try to write a program that controll a door, the door is build with remain in motion. (Pics)
ok heres the code and under the code is all what is in and whats not working, while my brain is on fire.

local component = require("component")
local sides = require("sides")
local colors = require("colors")
local redstone = component.redstone
local computer = require("computer")
oeffner = redstone.getBundledInput(sides.back, colors.magenta)
yellow = redstone.getBundledInput(sides.back, colors.yellow)
lime = redstone.getBundledInput(sides.back, colors.lime)


print("Willkommen im Türkontrollmodus")
if(yellow == 241 and lime == 243) then
print("Tür ist Zurzeit geschlossen")
elseif (yellow < 241 and lime < 243) then
print("Tür ist zurzeit geöffnet")
else
print("Tür steht in einem unbekannten Zustand")
end
print("Bitte warten, die Türsteuerung wird geladen.")
print("")
print("")
os.sleep(2)


print("Willkommen bei der Türsteuerung")
print("Bitte eingabe erfassen zum Tor öffnen(1) oder schließen(2)")
eingabe = io.read()
while not tonumber(eingabe) do
print("keine Nummer")
print("Bitte eine Ziffer von 0-9 Eingeben")
eingabe = io.read()
end

if (eingabe == "1" and yellow == 241 and lime == 243) then
print("Tür wird geöffnet")
redstone.setBundledOutput(sides.back, colors.lightblue, 255)
for i=1,5 do
redstone.setBundledOutput(sides.back, colors.orange, 255)
os.sleep(0.1)
redstone.setBundledOutput(sides.back, colors.orange, 0)
os.sleep(1)
end

elseif (eingabe == "2" and yellow < 241 and lime < 243) then
print("Tür wird geschlossen")
redstone.setBundledOutput(sides.back, colors.lightblue, 255)
for i=1,5 do
redstone.setBundledOutput(sides.back, colors.white, 255)
os.sleep(0.1)
redstone.setBundledOutput(sides.back, colors.white, 0)
os.sleep(1)
end

else
print("Eingabe nicht möglich, Nummer nicht verwendet, oder Tor bereits geöffnet/geschlossen")
print("Bitte erneut versuchen")
os.sleep(2)
computer.shutdown(true)
end

at this moment the programm works on this, but i want some things that i cant do, while i dont now how.

The First thing is, that i cant reset the ligthblue cable, it should reset when the for loop is by 5 i tryed it so:

if (eingabe == "1" and yellow == 241 and lime == 243) then
print("Tür wird geöffnet")
redstone.setBundledOutput(sides.back, colors.lightblue, 255)
for i=1,5 do
redstone.setBundledOutput(sides.back, colors.orange, 255)
os.sleep(0.1)
redstone.setBundledOutput(sides.back, colors.orange, 0)
if (i == "5") then
redstone.setBundledOutput(sides.back, colors.lightblue, 0)
end
os.sleep(1)
end

but it doesnt work.

The next think is
eingabe = io.read()
i want to kill the io.read if the input oeffner is true or has a signal from 230.

you see its not really computercraft, some thinks are other, but i want to try it on opencomputers.
and sorry for the bad language, i hope you can help me, if questions you can ask everytime.

The files are 8KB to big so i uploaded here

https://picload.org/....43.58.png.html
https://picload.org/....44.03.png.html
https://picload.org/....44.12.png.html
https://picload.org/....44.20.png.html
https://picload.org/....49.02.png.html
https://picload.org/....49.11.png.html
https://picload.org/....49.22.png.html
Edited on 27 June 2017 - 09:51 AM
Bomb Bloke #2
Posted 27 June 2017 - 02:35 PM
5 is not the same as "5". One is a number, the other is a string.

Cancelling read is trickier to solve; the parallel API is the simplest way to do it.
darcline #3
Posted 27 June 2017 - 04:05 PM
okey the first thing work, damn strings
the second uff i need to rewrite the program that can take a bit :/

thanks for the help bomb bloke, if its not working i made a new topic for the parallel api, if i not see any other way
TheRockettek #4
Posted 27 June 2017 - 05:59 PM
Also you dont need to require() anything as the base apis for computercraft are already loaded. By seeing that, i presume you used OpenComputers before ComputerCraft