Python Forum
probably a easy problem for you
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
probably a easy problem for you
#1
hi
im a total noob on this! but anyway... im trying to build a temp monitor for my reef tank. 
based on a rpi with lcd hat (non rgb)




 #!/usr/bin/python

# Import all the libraries
from Adafruit_CharLCDPlate import Adafruit_CharLCDPlate
from w1thermsensor import W1ThermSensor
import time

# Sample/Refresh time in seconds
refresh = 60

# Temperature history in values (history duration will be samples * refresh)
samples = 60

# Define and initialise the LCD
lcd = Adafruit_CharLCDPlate()

lcd.begin(16,1)
lcd.backlight(lcd.RED)
lcd.message("PiTemp!")

# degree symbol
lcd.createChar(1, [0b01100,
 0b10010,
 0b10010,
 0b01100,
 0b00000,
 0b00000,
 0b00000,
 0b00000])
# Diagonal up arrow
lcd.createChar(2, [0b00000,
 0b01111,
 0b00011,
 0b00101,
 0b01001,
 0b10000,
 0b00000,
 0b00000])
# Diagonal down arrow
lcd.createChar(3, [0b00000,
 0b10000,
 0b01001,
 0b00101,
 0b00011,
 0b01111,
 0b00000,
 0b00000])


# Define the temperature sensor
sensor = W1ThermSensor()

# Set up the history array
temp = sensor.get_temperature()
templist = [temp] * samples

try:
 while True:
 # Shift out the oldest temperature value
  for x in range(len(templist)-1):
 templist[x] = templist[x+1]
 # Set the end item to be our current temperature
 templist[len(templist)-1] = sensor.get_temperature()
 # Uncomment the following line for debugging
 #print "max %.2f min %.2f\n" % (max(templist),min(templist))

 # Display it on the LCD
 lcd.clear()
 lcd.message("""Temp %.2f \x01C\n\x02 %.2f \x03 %.2f""" %
 (templist[len(templist)-1],max(templist),min(templist)))

 # Sleep until we need to sample/refresh
 time.sleep(refresh)

except KeyboardInterrupt:
 print "Interrupted!\n"


lcd.clear()
lcd.message("PiTemp finished")

 
Error:
 } [b]pi@raspberrypi[/b]:[b]~ $[/b] sudo python tempntime.py   File "tempntime.py", line 60     for x in range(len(templist)-1):       ^ IndentationError: expected an indented block 
Reply
#2
Start with line 60 and work your way down and see if you can spot the problem. Hint #1- look at line 61.  Hint #2- use 4 spaces for indentation, not 1. It's a lot easier to follow.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#3
The error tells you exactly what the problem is, AND where that issue is. What do you need help with?
Reply
#4
(May-12-2017, 06:34 PM)nilamo Wrote: The error tells you exactly what the problem is, AND where that issue is.  What do you need help with?

Didn't I mention that I'm a total noob to this? Big Grin
The error tells me nothing. the code is copy/paste from the net
Reply
#5
(May-12-2017, 06:43 PM)krheigh Wrote: The error tells me nothing
It tells you your indentation is off, and follows that up by telling you a for loop expects an indented body.
Your for loop doesn't have a body.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Code problem - probably easy fix? colin_dent 5 950 Jun-30-2023, 01:55 PM
Last Post: deanhystad
  easy name problem Steinsack 1 1,766 Jun-16-2021, 02:03 PM
Last Post: snippsat
  Problem with very easy code. janekk9002 1 1,835 Dec-10-2020, 12:57 PM
Last Post: buran
  How to start with this easy problem? Fran 8 4,233 Sep-11-2018, 09:04 AM
Last Post: Fran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020