Example #1
0
def wait_a_bit():
  global i;
  i= (i+1) & 0xfff
  if(15==i & 15):
    sys.gc()     # clean up
  else:
    sys.wait(4)  # wait a bit
Example #2
0
    def clear(self):
        # clear display, set cursor position to zero
        self.command(LCD_CLEARDISPLAY)
        # this command takes a long time!
        sys.wait(2)  

        # clean up
        sys.gc()
Example #3
0
def i():
    print ch.next()
    gc()
Example #4
0
# Create some random rectangles
rectangles = []
for _ in xrange(10):
    list.append(rectangles, [rand() % screen_width, rand() % screen_height,
                             rand() % 40 + 20, rand() % 40 + 20,
                             (rand() % 0x40) * 0x10002 + 0x883388,
                             rand() % 7 - 3, rand() % 7 - 3])


# Clear screen
maSetColor(background_color)
maFillRect(0, 0, screen_width, screen_height)

keep_going = True
while keep_going:
    sys.gc()
    # Wait for an event, or 20 ms
    maWait(1)

    # Handle all events from the event queue
    for event in maGetEvents():
        print event.__str__()
        if (event.type == EVENT_TYPE_CLOSE or
            event.type == EVENT_TYPE_KEY_PRESSED and event.key == MAK_FIRE):
            keep_going = False

    # Erase rectangles
    maSetColor(background_color)
    for rectangle in rectangles:
        x, y, w, h, c, xv, yv = rectangle
        maFillRect(x-w, y-h, w, h)
Example #5
0
def wait_BTN_release():
  while 1==x.BTN(): # waiting for release USER BUTTON
    sys.gc()     # clean up
    sys.wait(100)
Example #6
0
      else:
        LED_all((a&0xff))
    else:
      if(a & 0x100):
        x.LED( (a>>9) & 3, (0x100-(a&0xff)))
      else:
        x.LED( (a>>9) & 3, (a&0xff))

def LED_axel_indicate(ax):
    LED_all()
    if(ax[1]>0): x.LED(0,ax[1]<<1 )
    if(ax[0]>0): x.LED(1,ax[0]<<1 )
    if(ax[1]<0): x.LED(2,(1-ax[1])<<1 )
    if(ax[0]<0): x.LED(3,(1-ax[0])<<1 )

sys.gc()

def gpio_demo() :
    """import gpio
    print "gpio imported"
    gpio.pin_mode(PE7, gpio.OUTPUT)
    print "looping"
    while True:
        gpio.digital_write(PE7, gpio.HIGH)
        gpio.digital_write(PE7, gpio.LOW)"""
    
    from gpio import pin_mode, digital_write, OUTPUT, INPUT, HIGH, LOW
    print "gpio imported"
    pin_mode("E", 7, OUTPUT)
    print "looping"
    while True:
Example #7
0
    def begin(self, cols, lines, dotsize=0):
        """
        """
        if lines > 1 :
            self._displayfunction |= LCD_2LINE

        self._numlines = lines
        self._currline = 0
        
        if dotsize != 0 and lines == 1 :
            self._displayfunction |= LCD_5x10DOTS

        # SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION!
        # according to datasheet, we need at least 40ms after power rises above 2.7V
        # before sending commands. Arduino can turn on way befer 4.5V so we'll wait 50
        # delayMicroseconds(50000); 
        sys.wait(50)

        # Now we pull both RS and R/W low to begin commands
        self.dg_write(self.rs_pin, gpio.LOW)
        self.dg_write(self.enable_pin, gpio.LOW)

        if self.rw_pin != 255 : 
              self.dg_write(self.rw_pin, gpio.LOW)

        # //put the LCD into 4 bit or 8 bit mode
        if not (self._displayfunction & LCD_8BITMODE) :
           # this is according to the hitachi HD44780 datasheet
           # figure 24, pg 46
           # we start in 8bit mode, try to set 4 bit mode
           self.write4bits(0x03)
           # wait min 4.1ms
           sys.wait(4)
           # second try
           self.write4bits(0x03)
           # wait min 4.1ms
           sys.wait(4)
           # third go!
           self.write4bits(0x03) 
           sys.wait(2)

           # finally, set to 4-bit interface
           self.write4bits(0x02) 
        else :
           # this is according to the hitachi HD44780 datasheet
           # page 45 figure 23

           # Send function set command sequence
           self.command(LCD_FUNCTIONSET | self._displayfunction)
           # wait more than 4.1ms
           sys.wait(5)
           # second try
           self.command(LCD_FUNCTIONSET | self._displayfunction)
           sys.wait(1)

           # third go
           self.command(LCD_FUNCTIONSET | self._displayfunction)

        # finally, set # lines, font size, etc.
        self.command(LCD_FUNCTIONSET | self._displayfunction)

        # turn the display on with no cursor or blinking default
        self._displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF

        self.display()

        # clear it off
        self.clear()

        # Initialize to default text direction (for romance languages)
        self._displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT

        # set the entry mode
        self.command(LCD_ENTRYMODESET | self._displaymode)

        # clean up
        sys.gc()
Example #8
0
def i():
    print ch.next()
    gc()
Example #9
0
# This file is Copyright 2010 Dean Hall.
#
# This file is part of the Python-on-a-Chip program.
# Python-on-a-Chip is free software: you can redistribute it and/or modify
# it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1.
#
# Python-on-a-Chip is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# A copy of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1
# is seen in the file COPYING up one directory from this.

#
# System Test 347
#

import string
from sys import gc
from t347b import *

print _bar()
print bar()
gc()
print 'did gc'
print _bar()
print bar()
Example #10
0
# This file is Copyright 2010 Dean Hall.
#
# This file is part of the Python-on-a-Chip program.
# Python-on-a-Chip is free software: you can redistribute it and/or modify
# it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1.
#
# Python-on-a-Chip is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# A copy of the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1
# is seen in the file COPYING up one directory from this.

#
# System Test 347
#

import string
from sys import gc
from t347b import *


print bar1()
print bar2()
gc()
print 'did gc'
print bar1()
print bar2()