Esempio n. 1
0
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
'''

import time
import bakebit

# Connect the buzzer to digital port D3
# SIG,NC,VCC,GND
buzzer = 3

bakebit.pinMode(buzzer,"OUTPUT")

while True:
    try:
	bakebit.analogWrite(buzzer,127)
        time.sleep(2)
        bakebit.analogWrite(buzzer,0)
	time.sleep(2)

    except KeyboardInterrupt:
        bakebit.analogWrite(buzzer,0)
        break

    except IOError:
        print ("Error")
Esempio n. 2
0
import requests

URL = 'http://localhost:8000/sensors'
 
# Connect the BakeBit Light Sensor to analog port A0
# SIG,NC,VCC,GND
light_sensor = 0
 
# Connect the LED to digital port D5
# SIG,NC,VCC,GND
led = 5

lowThreshold = 700
highTreshold = 1023

bakebit.pinMode(light_sensor,"INPUT")
bakebit.pinMode(led,"OUTPUT")
time.sleep(1)
 
# Reference voltage of ADC is 5v
adc_ref = 5

def send_to_server(type, value):
    try:
        payload = {"sensors": type, "value": value}
        print payload
        r = requests.post(URL, data=payload)
        print r.text
    except:
        print("Server Down")
Esempio n. 3
0
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
'''

import time
import bakebit

# Connect the BakeBit Sound Sensor to analog port A0
# SIG,NC,VCC,GND
sound_sensor = 0

# Connect the BakeBit LED to digital port D5
# SIG,NC,VCC,GND
led = 5

bakebit.pinMode(sound_sensor,"INPUT")
bakebit.pinMode(led,"OUTPUT")

# The threshold to turn the led on 400.00 * 5 / 1024 = 1.95v
threshold_value = 400

while True:
    try:
        # Read the sound level
        sensor_value = bakebit.analogRead(sound_sensor)

        # If loud, illuminate LED, otherwise dim
        if sensor_value > threshold_value:
            bakebit.digitalWrite(led,1)
        else:
            bakebit.digitalWrite(led,0)
Esempio n. 4
0
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
'''

import time
import bakebit
import random

# Connect the BakeBit LED Bar to digital port D3
# DI,DCKI,VCC,GND
ledbar = 3

bakebit.pinMode(ledbar,"OUTPUT")
time.sleep(.2)
i = 0
old_color = 0

bakebit.bakeBitLedBar_Init(ledbar, 0, 5)
time.sleep(.5)

while True:
    try:
        for i in range(0,5):
            color16bit = bakebit.Green
            if i >= 1:
                color16bit = color16bit | (bakebit.Green << 3)
            if i >= 2:
                color16bit = color16bit | (bakebit.Green << 6)
Esempio n. 5
0
'''

import time
import bakebit

# Connect the BakeBit LED to digital port D5
# SIG,NC,VCC,GND
led = 5

# Digital ports that support Pulse Width Modulation (PWM)
# D3, D5, D6

# Digital ports that do not support PWM
# D2, D4, D7, D8

bakebit.pinMode(led, "OUTPUT")
time.sleep(1)
i = 0

while True:
    try:
        # Reset
        if i > 255:
            i = 0

        # Current brightness
        print(i)

        # Give PWM output to LED
        bakebit.analogWrite(led, i)
Esempio n. 6
0
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
'''
import time
import bakebit

# Connect the BakeBit Button to digital port D3
# SIG,NC,VCC,GND
button = 3

bakebit.pinMode(button, "INPUT")

while True:
    try:
        print(bakebit.digitalRead(button))
        time.sleep(.5)

    except IOError:
        print("Error")
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
'''

import time
import bakebit

# Connect the BakeBit Thumb Joystick to analog port A0
# If you wish to connect two joysticks, use ports A0 and A2 (skip A1)

# Uses two pins - one for the X axis and one for the Y axis
# This configuration means you are using port A0
xPin = 0
yPin = 1
bakebit.pinMode(xPin, "INPUT")
bakebit.pinMode(yPin, "INPUT")

while True:
    try:
        # Get X/Y coordinates
        x = bakebit.analogRead(xPin)
        y = bakebit.analogRead(yPin)
        print("x =", x, " y =", y)
        time.sleep(.5)

    except IOError:
        print("Error")
Esempio n. 8
0
import time
import bakebit

# Connect the BakeBit Rotary Angle Sensor to analog port A0
# SIG,NC,VCC,GND
potentiometer = 0

# Connect the LED to digital port D5
# SIG,NC,VCC,GND
led = 5

bakebit.pinMode(potentiometer, "INPUT")
bakebit.pinMode(led, "OUTPUT")
time.sleep(1)

# Reference voltage of ADC is 5v
adc_ref = 5

# Vcc of the BakeBit interface is normally 5v
bakebit_vcc = 5

# Full value of the rotary angle is 300 degrees, as per it's specs (0 to 300)
full_angle = 300

while True:
    try:
        # Read sensor value from potentiometer
        sensor_value = bakebit.analogRead(potentiometer)

        # Calculate voltage
        voltage = round((float)(sensor_value) * adc_ref / 1023, 2)
Esempio n. 9
0
# Connect the BakeBit Rotary Angle Sensor to analog port A0
# SIG,NC,VCC,GND
potentiometer = 0

# Reference voltage of ADC is 5v
adc_ref = 5

# Vcc of the bakebit interface is normally 5v
bakebit_vcc = 5

# Full value of the rotary angle is 180 degrees, as per it's specs (0 to 180)
full_angle = 180
old_degrees = -1

bakebit.pinMode(potentiometer, "INPUT")
bakebit.bakeBitServo_Attach(servo)

while True:
    try:
        # Read sensor value from potentiometer
        sensor_value = bakebit.analogRead(potentiometer)

        # Calculate voltage
        voltage = round((float)(sensor_value) * adc_ref / 1023, 2)

        # Calculate rotation in degrees (0 to 180)
        degrees = int((voltage * full_angle) / bakebit_vcc)

        if degrees != old_degrees:
            print("sensor_value = %d voltage = %.2f degrees = %d" %