1. How to make a clock in Python

    This little script shows the time in a window.

    '''Import libraries'''
    from Tkinter import *
    import time
    
    '''Define a function'''
    def tick():
        '''Assign current time to time_string'''
        time_string = time.strftime("%H:%M:%S")
    
        '''Update the clock labels text'''
        clock.config(text=time_string)
    
        '''After 200ms run tick'''
        clock.after(200, tick)
    
    '''Make …
    read more
  2. Python - How to load a file and convert it base64

    This python script creates a window with four buttons, two labels and a text widget. The code is fairly good commented and speaks for itself. The coded file will be written as a text file.

    import Tkinter, Tkconstants, tkFileDialog
    from Tkinter import *
    import tkMessageBox
    import base64
    import webbrowser
    
    def exit …
    read more
  3. Raspberry Pi - RPM/Tacho meter

    This little program count the rising edges of an IR sensor connected to GPIO 21.

    import RPi.GPIO as GPIO
    import time
    
    sensor = 21
    
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(sensor, GPIO.IN)
    
    sample = 100
    count = 0
    
    start = 0
    end = 0
    
    def set_start():
        global start
        start = time.time()
    
    
    def set_end …
    read more
  4. Raspberry Pi,2 x 16 LCD and web scraping

    This program log on to a website, and get som information.

    The import block:

    1
    2
    3
    4
    5
    6
    #!/usr/bin/python
    import time
    from time import gmtime, strftime
    import socket
    import Adafruit_CharLCD as LCD
    import requests
    

    Assignment:

    time_counter = 0
    
    lcd_rs  = 25
    lcd_en  = 24
    lcd_d4  = 23
    lcd_d5  = 17
    lcd_d6 …
    read more

« Page 2 / 3 »

blogroll

social