Esempio n. 1
0
    def run(self):
        grove_oled.oled_init()
        grove_oled.oled_clearDisplay()
        grove_oled.oled_setNormalDisplay()
        grove_oled.oled_setVerticalMode()
        self.show("Amybot!")

        try:
            LOGGER.info('Press CTRL+C to quit')
            running = True
            # Loop indefinitely
            while running:
                # Get the latest events from the system
                had_event = False
                events = pygame.event.get()
                # Handle each event individually
                for event in events:
                    if event.type == pygame.QUIT:
                        # User exit
                        running = False
                        break
                    elif event.type == pygame.JOYBUTTONDOWN:
                        # A button on the joystick just got pushed down
                        self.mode = event.button
                        if event.button == R2_BUTTON:
                            self.straight_line_start = not self.straight_line_start
                try:
                    self.modes[self.mode]()
                except KeyError:
                    LOGGER.warning("No mode set for key %i", self.mode)
                    self.mode = R1_BUTTON
                time.sleep(INTERVAL)

        except KeyboardInterrupt:
            # CTRL+C exit, disable all drives
            self.bot.move(0, 0)
            self.show('Motors off')
Esempio n. 2
0
import time
import grove_temperature_sensor
import grove_oled
import Adafruit_BBIO.GPIO as GPIO

dweetIO = "https://dweet.io/dweet/for/"
myName = "BBG_IoT_Demo"
myKey = "Temperature"

Buzzer = "P9_22"  # UART2_RXD P9_22
GPIO.setup(Buzzer, GPIO.OUT)
THRESHOLD_TEMPERATURE = 30

if __name__ == "__main__":

    grove_oled.oled_init()
    grove_oled.oled_setNormalDisplay()
    grove_oled.oled_clearDisplay()
    while True:
        # GPIO.output(led,GPIO.HIGH)
        # time.sleep(1)
        # GPIO.output(led,GPIO.LOW)
        # time.sleep(1)
        # print 'led'
        temperature = grove_temperature_sensor.read_temperature()

        grove_oled.oled_setTextXY(0, 0)
        grove_oled.oled_putString('Temp:{0:0.1f} *C'.format(temperature))
        grove_oled.oled_setTextXY(5, 0)
        grove_oled.oled_putString("SeeedStudio")
#This is a demo to get your city/town weather from http://openweathermap.org/ to display on Grove OLED
#by Carmelito Andrade
#sudo pip install pyowm
#Create an account on http://openweathermap.org/ and get the API key
import time
import grove_oled
import pyowm
APIKey = 'XXXXXXXXXXXXXXXXXXXXXXXXXX'
placeName = 'Toronto,CA' #change this to your city name

owm = pyowm.OWM(APIKey)

grove_oled.oled_init()
grove_oled.oled_setNormalDisplay()
grove_oled.oled_clearDisplay()

while True:
	observation = owm.weather_at_place(placeName)	
	weatherData = observation.get_weather()
	temperature = weatherData.get_temperature(unit='celsius')['temp']
	humidity = weatherData.get_humidity()
	weatherCondition = weatherData.get_status()
	#printing weather on the OLED
	grove_oled.oled_setTextXY(0,0)
	grove_oled.oled_putString(placeName)
	grove_oled.oled_setTextXY(2,0)
	grove_oled.oled_putString('Temp :'+ str(temperature) +'C')
	grove_oled.oled_setTextXY(4,0)
	grove_oled.oled_putString('Humid:'+ str(humidity) +'%')
	grove_oled.oled_setTextXY(6,0)
	grove_oled.oled_putString("- Weather -")