0% found this document useful (0 votes)
10 views4 pages

Iot Codes

Uploaded by

sanasayyad2112
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views4 pages

Iot Codes

Uploaded by

sanasayyad2112
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Matrix

import re
import time
import argparse
from luma.led_matrix.device import max7219
from luma.core.interface.serial import spi, noop
from luma.core.render import canvas
from luma.core.virtual import viewport
from luma.core.legacy import text, show_message
from luma.core.legacy.font import proportional, CP437_FONT, TINY_FONT

def demo(n, block_orientation, rotate, inreverse):


# create matrix device
serial = spi(port=0, device=0, gpio=noop())
device = max7219(serial, cascaded=n or 1, block_orientation=block_orientation, rotate=rotate or 0,
blocks_arranged_in_reverse_order=inreverse)
print("Created device")

# start demo
msg = "TYITA"
print(msg)
show_message(device, msg, fill="white", font=proportional(CP437_FONT),scroll_delay=0.1)
time.sleep(1)

device.contrast(0x80)
time.sleep(1)

if __name__ == "__main__":
parser = argparse.ArgumentParser(description='matrix_demo arguments',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)

parser.add_argument('--cascaded', '-n', type=int, default=1, help='Number of cascaded devices')


parser.add_argument('--block-orientation', type=int, default=0, choices=[0, 90, -90], help='Block orientation')
parser.add_argument('--rotate', type=int, default=0, choices=[0, 1, 2, 3], help='Rotate display')
parser.add_argument('--reverse-order', type=bool, default=False, help='Reverse block order')

args = parser.parse_args()

try:
while True:
demo(args.cascaded, args.block_orientation, args.rotate, args.reverse_order)
except KeyboardInterrupt:
pass
Display time Oscilloscope

from time import sleep import time


import tm1637 import matplotlib.pyplot as plt
from drawnow import *
import Adafruit_ADS1x15
adc=Adafruit_ADS1x15.ADS1115()
try:
GAIN=1
import thread
val=[]
except ImportError: cnt=0
import _thread as thread plt.ion()
adc.start_adc(0,gain=GAIN)
Display = tm1637.TM1637(CLK=21, DIO=20, brightnes=1.0) print('Reading ADS1x15 channel 0')
def makeFig():
try: plt.ylim(-5000,5000)
plt.title('Osciloscope')
print("Starting clock in the background:")
plt.grid(True)
Display.StartClock(military_time=True)
plt.ylabel('ADC outputs')
plt.plot(val,'ro-',label='Channel 0')
while True: plt.legend(loc='lower right')
Display.ShowDoublepoint(True) while(True):
sleep(1) value=adc.get_last_result()
Display.ShowDoublepoint(False) print('Channel 0:{0}'.format(value))
sleep(1) time.sleep(0.5)
val.append(int(value))
drawnow(makeFig)
Display.StopClock() plt.pause(.000001)
thread.interrupt_main() cnt=cnt+1
except KeyboardInterrupt: if(cnt>50):
print("properly closing the clock and open GPIO pins") val.pop(0)

Display.cleanup()
Telegram

import sys
import time
import random
import datetime
import telepot
import RPi.GPIO as GPIO
from telepot.loop import MessageLoop

red=40
now=datetime.datetime.now()
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)

GPIO.setup(red,GPIO.OUT)
GPIO.output(red,0)

def action(msg):
chat_id=msg['chat']['id']
command=msg['text']

print('got command :%s'%command)


if 'On' in command:
message="TURN ON"
message=message+"red"
GPIO.output(red,1)
bot.sendMessage(chat_id,message)

if 'Off' in command:
message="TURN Off"
message=message+"red"
GPIO.output(red,0)
bot.sendMessage(chat_id,message)

bot=telepot.Bot('7275698452:AAFxbC85OdoT2nGeTf-xy7ZMA9bXkGNjtLI')

print(bot.getMe())
MessageLoop(bot,action).run_as_thread()
print('I am listening...')

while 1:
time.sleep(10)
import time

import board

import digitalio

import adafruit_character_lcd.character_lcd as char_lcd

lcd_columns = 16

lcd_rows = 2

lcd_rs = digitalio.DigitalInOut(board.D26)

lcd_en = digitalio.DigitalInOut(board.D19)

lcd_d4 = digitalio.DigitalInOut(board.D25)

lcd_d5 = digitalio.DigitalInOut(board.D24)

lcd_d6 = digitalio.DigitalInOut(board.D22)

lcd_d7 = digitalio.DigitalInOut(board.D27)

lcd_backlight = digitalio.DigitalInOut(board.D4)

lcd = char_lcd.Character_LCD_Mono(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, lcd_columns, lcd_rows, lcd_backlight)

lcd.message = "IOT Practical"

time.sleep(5)

lcd.clear()

You might also like