try: input = raw_input except NameError: pass try: unichr = unichr except NameError: unichr = chr lcd = CharLCD(cols=16, rows=2) # if you have a backlight circuit, initialize like this (substituting the # appropriate GPIO and BacklightMode for your backlight circuit): #lcd = CharLCD(cols=16, rows=2, pin_backlight=7, backlight_mode=BacklightMode.active_high) lcd.backlight = True input('Display should be blank. ') lcd.cursor_mode = CursorMode.blink input('The cursor should now blink. ') lcd.cursor_mode = CursorMode.line input('The cursor should now be a line. ') lcd.write_string('Hello world!') input('"Hello world!" should be on the LCD. ') assert lcd.cursor_pos == (0, 12), 'cursor_pos should now be (0, 12)' lcd.cursor_pos = (0, 15) lcd.write_string('1')
input = raw_input except NameError: pass try: unichr = unichr except NameError: unichr = chr lcd = CharLCD(cols=16, rows=2) # if you have a backlight circuit, initialize like this (substituting the # appropriate GPIO and BacklightMode for your backlight circuit): #lcd = CharLCD(cols=16, rows=2, pin_backlight=7, backlight_mode=BacklightMode.active_high) lcd.backlight = True input('Display should be blank. ') lcd.cursor_mode = CursorMode.blink input('The cursor should now blink. ') lcd.cursor_mode = CursorMode.line input('The cursor should now be a line. ') lcd.write_string('Hello world!') input('"Hello world!" should be on the LCD. ') assert lcd.cursor_pos == (0, 12), 'cursor_pos should now be (0, 12)' lcd.cursor_pos = (0, 15) lcd.write_string('1')
def read_temp_f(): lines = read_temp_raw() while lines[0].strip()[-3:] != 'YES': time.sleep(0.2) lines = read_temp_raw() equals_pos = lines[1].find('t=') if equals_pos != -1: temp_string = lines[1][equals_pos+2:] temp_f = (int(temp_string) / 1000.0) * 9.0 / 5.0 + 32.0 # TEMP_STRING IS THE SENSOR OUTPUT, MAKE SURE IT'S AN INTEGER TO DO THE MATH temp_f = str(round(temp_f, 1)) # ROUND THE RESULT TO 1 PLACE AFTER THE DECIMAL, THEN CONVERT IT TO A STRING return temp_f void setup(void) { lcd.init(); // initialize the lcd lcd.backlight(); Serial.begin(9600) sensors.begin(); // turn on sensors for DS18b20 pinMode(buttonUp, INPUT); // Set INCREASE button to input pinMode(buttonDown, INPUT); // Set DECREASE button to input lcd.setCursor(0,0); // Set LCD cursor to first cursor spot lcd.print("Temperature"); // Print "Temperature" to cursor spot on LCD } void loop(void) { sensors.requestTemperatures(); // Get temperature readings lcd.setCursor(2,1); lcd.print(sensors.getTempFByIndex(0)); // Print actual temperature