1 Replies - 380 Views - Last Post: 18 December 2012 - 09:39 AM Rate Topic: -----

#1 Fu-King  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 17-December 12

Printing All Sensor values

Posted 18 December 2012 - 08:57 AM

So, I've tried a few ways to make it print all the values but it's not working... Can someone help please?


 from myro import*
init("simulator")

lightLeft = getLight("left")
lightCenter = getLight("center")
lightRight = getLight("right")

def pressC():
    key = "x"
    while key != "C":
        key = raw_input("Enter C to continue: ")


def main():
    senses()
    pressC()
	
    Leftsensorvalues = []
    Centersensorvalues = []
    Rightsensorvalues = []
    
    forward(1,1)
    
    for i in range(20):
        turnLeft(.35,1)
        lightLeft
        Leftsensorvalues.append(lightLeft)
        
        lightCenter
        Centersensorvalues.append(lightCenter)
        
        lightRight
        Rightsensorvalues.append(lightRight)
    
    print "Left Sensor Values:" + str(Leftsensorvalues)
    print "Center Sensor Values:" + str(Centersensorvalues)
    print "Right Sensor Values:" + str(Rightsensorvalues)
	
    Leftaverage = sum(Leftsensorvalues) / 15
    Centeraverage = sum(Centersensorvalues) / 15
    Rightaverage = sum(Rightsensorvalues) / 15
	
    print "Left average:" + str(Leftaverage)
    print "Center average:" + str(Centeraverage)
    print "Right average" + str(Rightaverage)

main()



Is This A Good Question/Topic? 0
  • +

Replies To: Printing All Sensor values

#2 Nallo  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 163
  • View blog
  • Posts: 255
  • Joined: 19-July 09

Re: Printing All Sensor values

Posted 18 December 2012 - 09:39 AM

I do not know myro. So just a wild guess:

In line 26 (also in 29, 32) you actually wanted to write:
lightLeft = getLight("left")


Just writing
lightLeft

does nothing. It is just a variable name and you do nothing with it.
So in your next line
Leftsensorvalues.append(lightLeft)

only the value you read at the very beginning gets appended to your list.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1