def init(mode): print("Selected mode: " + str(mode)) if mode < 0 or mode > 3: raise ModeError(mode) global MODE MODE = mode GPIO.init() GPIO.setcfg(MOSI, OUT) GPIO.setcfg(MISO, IN) GPIO.setcfg(SCK, OUT) GPIO.setcfg(CS, OUT) if mode == 0 or mode == 1: GPIO.output(CS, HIGH) GPIO.output(SCK, LOW) GPIO.output(MOSI, LOW) else: GPIO.output(CS, HIGH) GPIO.output(SCK, HIGH) GPIO.output(MOSI, HIGH) return
def init(mode): print ("Selected mode: " + str(mode)) if mode < 0 or mode > 3: raise ModeError(mode); global MODE MODE = mode GPIO.init() GPIO.setcfg(MOSI, OUT) GPIO.setcfg(MISO, IN) GPIO.setcfg(SCK, OUT) GPIO.setcfg(CS, OUT) if mode == 0 or mode == 1: GPIO.output(CS, HIGH) GPIO.output(SCK, LOW) GPIO.output(MOSI, LOW) else: GPIO.output(CS, HIGH) GPIO.output(SCK, HIGH) GPIO.output(MOSI, HIGH) return
def init_pins(all_pins): #init module GPIO.init() for pin in all_pins: #configure module cfgs = all_pins[pin] GPIO.setcfg(pin, cfgs[0]) config = GPIO.getcfg(cfgs[0]) GPIO.output(pin, cfgs[1]) GPIO.output(mr_pin, GPIO.HIGH)
def enable(self, intensity=7): GPIO.init() GPIO.setcfg(self.dio, GPIO.OUT) GPIO.setcfg(self.clk, GPIO.OUT) GPIO.setcfg(self.stb, GPIO.OUT) GPIO.output(self.stb, GPIO.HIGH) GPIO.output(self.clk, GPIO.HIGH) self.send_command(0x40) self.send_command(0x80 | 8 | min(7, intensity)) GPIO.output(self.stb, GPIO.LOW) self.send_byte(0xC0) for i in range(16): self.send_byte(0x00) GPIO.output(self.stb, GPIO.HIGH)
def enable(self, intensity=7): GPIO.init() GPIO.setcfg(self.dio, GPIO.OUT) GPIO.setcfg(self.clk, GPIO.OUT) GPIO.setcfg(self.stb, GPIO.OUT) GPIO.output(self.stb,GPIO.HIGH) GPIO.output(self.clk,GPIO.HIGH) self.send_command(0x40) self.send_command(0x80 | 8 | min(7, intensity)) GPIO.output(self.stb,GPIO.LOW) self.send_byte(0xC0) for i in range(16): self.send_byte(0x00) GPIO.output(self.stb,GPIO.HIGH)
def motor_init(): if not GPIO.init(): print "please run using root privilege." return False for gpio in GPIOS: GPIO.setcfg(gpio, GPIO.OUT) return True
def Init (clock = SPICLK, miso = SPIMISO, mosi = SPIMOSI, cs = SPICS, min_channel = 0, max_channel = 2, vref = VREF, apply_voltage_divider = APPLY_VOLTAGE_DIVIDER, r = RESISTANCES): ''' clock: indicates clock pin miso: indicates master input slave output pin mosi: indicates master input slave output pin cs: chip selection pin min_channel: indicates the minimum channel where receive the analog inputs min_channel: indicates the maximum channel where receive the analog inputs apply_voltage_divider: indicates wether to apply the voltage divider in the calc of the read voltage r1: value of the R1 resistance in the voltage divider r2: value of the R2 resistance in the voltage divider ''' ADC = {} ADC['clk'] = clock ADC['miso'] = miso ADC['mosi'] = mosi ADC['cs'] = cs ADC['vref'] = vref ADC['voltage_div'] = apply_voltage_divider ADC['r'] = r ADC['error'] = (False, None) if ((max_channel > 7) or (min_channel < 0)): ADC['error'] = (True, "Unable to create the ADC. The values for the channels are not in the range (0,7)") return ADC ADC['maxch'] = max_channel ADC['minch'] = min_channel # set up the SPI interface pins GPIO.init () GPIO.setcfg(mosi, GPIO.OUT) GPIO.setcfg(miso, GPIO.IN) GPIO.setcfg(clock, GPIO.OUT) GPIO.setcfg(cs, GPIO.OUT) return ADC
def setup_leds(): global RED_LED global GREEN_LED global YELLOW_LED RED_LED = GPIO.PG5 GREEN_LED = GPIO.PG1 YELLOW_LED = GPIO.PG2 GPIO.init() GPIO.setcfg(RED_LED, GPIO.OUT) GPIO.setcfg(GREEN_LED, GPIO.OUT) GPIO.setcfg(YELLOW_LED, GPIO.OUT) NOK_ON() OK_ON() STATUS_ON() time.sleep(1) NOK_OFF() OK_OFF()
import SUNXI_GPIO as GPIO import time RED_LED = GPIO.PD0 GPIO.init() GPIO.setcfg(RED_LED, GPIO.OUT) while True: GPIO.output(RED_LED, GPIO.HIGH) print 'high' time.sleep(1) GPIO.output(RED_LED, GPIO.LOW) print 'low' time.sleep(1)
import SUNXI_GPIO as GPIO import time RED_LEDS = (GPIO.PG0, GPIO.PG1, GPIO.PG2, GPIO.PG3, GPIO.PG4, GPIO.PG5, GPIO.PG6, GPIO.PG7, GPIO.PC19, GPIO.PC20, GPIO.PC21, GPIO.PC22, GPIO.PB18, GPIO.PB19) GPIO.init() for led in RED_LEDS: GPIO.setcfg(led, GPIO.OUT) GPIO.output(led, GPIO.HIGH) time.sleep(0.3) GPIO.output(led, GPIO.LOW)