10 posts
Posted 02 September 2012 - 07:41 PM
Hi,
i have red the Lula tutorials but Iam not able to figure out how can I get the info from the ccSensors.
I dont have any skill in programing but it seems to be fun. Does anybody has a clue how to do an automatic lights system using ingame computer?
I have sensor controller next to console. I am able to get the sensors readings but when i tried to write some simple program i allways got the some error.
I didnt find any examples yet..
864 posts
Location
Sometime.
Posted 02 September 2012 - 09:20 PM
GETTING STARTED
1. place a Sensor Controller next to a computer
2. open the sensor Controller GUI and hit the "Request new CFreq" button to register a new freq
3. place blank transmitter card in the slot and click "Encode Transmitter"
to get an encoded transmitter to be used with the remote sensor.
4. Place a Remote Sensor (can be placed anywhere) and put the transmitter card in the bottom slot.
(you can rename the Remote Sensor from the default name "Sensor")
5. Place a SensorModule card into the top slot.
6. open the computer terminal and run: /ccSensors/console to run the sample console program.
That's it - you now have a working sensor connected to a computer :D/>/>
That should help, its how to build it. Can I see your code that you have tried?
10 posts
Posted 02 September 2012 - 09:37 PM
Thanx for yours advice.
Everything runs ok. On the computer I use the "Console" command so I can see the data from the sensor. I thought that I could use the variables (true/false) like this. On the same computer I made program "lights".
–
if sensors.isDaytime() == true then
redstone.setOutput ("left", true)
else
redstone.setOutput("left", false)
end
–
As I wrote, I dont know how to write programs, so it is probably wrong.
864 posts
Location
Sometime.
Posted 02 September 2012 - 09:44 PM
Its not wrong.
rs.setOutput("left", false) Turns redstone off
rs.setOutput("left", true) Turns redstone on
rs is redstone, just a clone.
You even got camelCasing right for a beginner, nice.
I don't know the ccSensors API but it looks correct? (Someone correct me)
Tips:
You don't need '== true'
10 posts
Posted 12 September 2012 - 09:51 PM
Hi there,
so I keep fighting but succes seems to be very far. I made light sensor on the right side of PC and placed lamp on the left side.
–Program lights
if rs.getInput("right") then
rs.setOutput("left", false)
end
if not rs.getInput("right") then
rs.setOuput("left", true) – the light should turn on
end
All Iam getting is : attempt to call nill, any hints?
3790 posts
Location
Lincoln, Nebraska
Posted 12 September 2012 - 10:14 PM
Attempt to call nil should include a number which points to the line the error is on. What line is it on? You may have misspelled a function or variable. (i do this all the time)
10 posts
Posted 13 September 2012 - 07:36 PM
Thanks,
misstake was in missig T letter in rs.setOutput.
Now I need to make this program run in a loop. I tried this:
repeat
local event = 1
if rs.getInput("right") then
rs.setOutput("left", false)
end
if not rs.getInput("right") then
rs.setOutput("left", true)
end
until event=="0"
but Iam getting this error: line 10: too long without yelding. I think its some basic misstake, any tips?
3790 posts
Location
Lincoln, Nebraska
Posted 13 September 2012 - 08:41 PM
You can make a loop with while true do or the way you have it. CC closes out anything that is repeating forever after a short time. You can "trick" the code into thinking that it is waiting at some point, by adding sleep(0) in there, or you can increase the interval if you want.
10 posts
Posted 13 September 2012 - 09:16 PM
Thx for your advice…now It works, but only for short period of time. After firt change of input singal (from 0 to 1) the program terminates displaying this:
startup 5: too long without yielding
my code:
while true do
if rs.getInput("right") then
rs.setOutput("left", false)
end
if not rs.getInput("right") then
rs.setOutput("left", true)
sleep(0)
end
end
3790 posts
Location
Lincoln, Nebraska
Posted 13 September 2012 - 09:19 PM
You put the sleep within your if statement. One more line down should work. Between the last two "end"s
10 posts
Posted 15 September 2012 - 09:45 AM
You put the sleep within your if statement. One more line down should work. Between the last two "end"s
Man, I love you !! :)/>/>
Thanks, it runs like a baby after first chili…