Demo entry 6356855

py

   

Submitted by anonymous on Apr 20, 2017 at 15:29
Language: Python. Code size: 1.2 kB.

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from sys import argv
import RPi.GPIO as GPIO
import zbar
import time

GPIO.setmode(GPIO.BOARD)

GPIO.setwarnings(False)

# cleanup
GPIO.cleanup()

#setup pins

GPIO.setup(11, GPIO.OUT)
GPIO.setup(12, GPIO.OUT)


#all off


GPIO.output(11, False) # red 2
GPIO.output(12, False) # red 1




# create a Processor
proc = zbar.Processor()

# configure the Processor
proc.parse_config('enable')

# initialize the Processor
device = '/dev/video0'
if len(argv) > 1:
    device = argv[1]
proc.init(device)

# enable the preview window
proc.visible = True

# read at least one barcode (or until window closed)
for n in range(1, 5):
	proc.process_one()
	
# hide the preview window
proc.visible = False

# extract results


for symbol in proc.results:
    # do something useful with results
    print 'decoded', symbol.type, 'symbol', '"%s"' % symbol.data

if (symbol.data == "LedRedON")
	GPIO.output(11, False) # turn led red  on
	GPIO.output(12, True) # turn green red off

elif (symbol.data == "ledRedOFF"):
	GPIO.output(11, False) # turn led red off
	GPIO.output(12, False) # turn green red on

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).