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

Need help with sensors displaying info on a monitor!

Started by Shehab19, 04 October 2014 - 01:28 PM
Shehab19 #1
Posted 04 October 2014 - 03:28 PM
Hey, im a complete noob when it comes to sensors and i cant seem to figure it out through the few tutorials that are on the internet. i have this code i wanna use to monitor combustion engine heat and maybe later use it to see how full a tank of fuel is. it doesnt work all i wanna do is display the data on a screen :/ take a look and tell me how to proceed please! my sensor is named sensor if it helps. this is in tekkit classic too.
——————–
os.unloadAPI("sensors")
os.loadAPI("/rom/apis/sensors")

function printDict(data)
for 1,v in pairs (data) do
print (tostring(1).." - "..tostring(v))
end
end

ctrl = getReading(left,sensor)
print(getReading(left,sensor)
end
Hiran #2
Posted 04 October 2014 - 04:47 PM

print(getReading(left,sensor)
you forgot second ")" in this line to close print.


for 1,v in pairs (data) do
Im almost sure that you cant use 1 here. use only chars.

other than that i dont know, as i dont have sensors.
Edited on 04 October 2014 - 02:49 PM
Dragon53535 #3
Posted 04 October 2014 - 10:07 PM
Another 2 errors after you fix the ones that Hiran pointed out.

getReading(left,sensor)
Should be

sensors.getReading("left","Sensor") --#If the sensor's name is capitalized with a capital S then this will work, otherwise change it to "sensor"

Simply because getReading() isn't a function in your program however it is a function inside the sensors API that you're loading, and so it's called as sensors.getReading()
sensors.getReading() accepts 2 parameters, the string side of the sensor controller, and the string name of the connected sensor. So you need quotes.
Shehab19 #4
Posted 05 October 2014 - 09:15 AM
Another 2 errors after you fix the ones that Hiran pointed out.

getReading(left,sensor)
Should be

sensors.getReading("left","Sensor") --#If the sensor's name is capitalized with a capital S then this will work, otherwise change it to "sensor"

Simply because getReading() isn't a function in your program however it is a function inside the sensors API that you're loading, and so it's called as sensors.getReading()
sensors.getReading() accepts 2 parameters, the string side of the sensor controller, and the string name of the connected sensor. So you need quotes.
okay if eliminated some errors but it still wont print on my monitor and i get this error : sensors:158: no such method getSensorsReading

os.unloadAPI("sensors")
os.loadAPI("/rom/apis/sensors")

function printDict(data)
for a,v in pairs (data) do
print (tostring(a).." - "..tostring(v))
end
end

reading = sensors.getReading("left","Sensor")
print(sensors.getReading("left","Sensor"))
Edited on 05 October 2014 - 07:19 AM
Hiran #5
Posted 05 October 2014 - 10:26 AM
Another 2 errors after you fix the ones that Hiran pointed out.

getReading(left,sensor)
Should be

sensors.getReading("left","Sensor") --#If the sensor's name is capitalized with a capital S then this will work, otherwise change it to "sensor"

Simply because getReading() isn't a function in your program however it is a function inside the sensors API that you're loading, and so it's called as sensors.getReading()
sensors.getReading() accepts 2 parameters, the string side of the sensor controller, and the string name of the connected sensor. So you need quotes.
okay if eliminated some errors but it still wont print on my monitor and i get this error : sensors:158: no such method getSensorsReading

os.unloadAPI("sensors")
os.loadAPI("/rom/apis/sensors")

function printDict(data)
for a,v in pairs (data) do
print (tostring(a).." - "..tostring(v))
end
end

reading = sensors.getReading("left","Sensor")
print(sensors.getReading("left","Sensor"))
It looks to me like issue within sensors. can you upload sensors api on pastebin so we could take a look into it?