Ejemplo n.º 1
0
def main():
	""" メイン関数 """
	# 接続ピン
	PIN_LD = 23
	# A/D変換チャネル数
	NUM_CH = 4
	
	# 赤色LED設定(PWM)
	red = PWMLED(PIN_LD)
	# フォトリフレクタ(複数)設定(A/D変換)
	photorefs = [ MCP3004(channel=idx) for idx in range(0,NUM_CH) ]
	
	# ループ処置
	while True:
		# 計測値平均の初期化
		ave = 0.0
		# 計測データの取得
		for idx in range(0,NUM_CH):
			pr = photorefs[idx]
			v = pr.value
			ave += v
			print('{}:{:4.2f} '.format(idx+1,v),end=' ')
		print()
		# 計測データの平均をLEDに出力
		red.value = ave/NUM_CH
		# 0.1秒待機
		sleep(0.1)
Ejemplo n.º 2
0
def main():
    """ メイン関数 """
    # 接続ピン
    PIN_LD = 23
    # A/D変換チャネル数
    NUM_CH = 4

    # 赤色LED設定(PWM)
    red = PWMLED(PIN_LD)
    # フォトリフレクタ(複数)設定(A/D変換)
    photorefs = [MCP3004(channel=idx) for idx in range(NUM_CH)]

    # 計測データ平均をLED入力に接続
    red.source = averaged(photorefs[0], photorefs[1], photorefs[2],
                          photorefs[3])

    # 停止(Ctrl+c)まで待機
    pause()
Ejemplo n.º 3
0
def main():
    """ メイン関数 """
    # モータードライバ接続ピン
    PIN_AIN1 = 6
    PIN_AIN2 = 5
    PIN_BIN1 = 26
    PIN_BIN2 = 27

    # A/D変換チャネル数
    NUM_CH = 4

    # 左右モーター設定(PWM)
    motors = Robot(left=(PIN_AIN1,PIN_AIN2), \
                   right=(PIN_BIN1,PIN_BIN2), \
                   pwm=True)
    # フォトリフレクタ(複数)設定(A/D変換)
    photorefs = [MCP3004(channel=idx) for idx in range(NUM_CH)]

    # ライントレース処理
    motors.source = line_follow(photorefs)

    # 停止(Ctr+c)まで待機
    pause()
Ejemplo n.º 4
0
import time
from gpiozero import MCP3004

while True:
    pot1 = MCP3004(0)
    print("pot1: "+ str(pot1.value))
    pot2 = MCP3004(1)
    print("pot2: "+ str(pot2.value))
    time.sleep(1)
Ejemplo n.º 5
0
'''

#导入ADC模块
from gpiozero import MCP3004

#导入luma相关库,oled lib
from luma.core.render import canvas
from luma.oled.device import ssd1306

from time import sleep

#初始化oled,I2C接口1,oled地址是0x3c
device = ssd1306(port=1, address=0x3C)

#初始化ADC模块,传感器接到CH1
adc = MCP3004(channel=1)

while True:

    V = adc.value * 3.3  #采集范围:0-1,转成电压值 0-3.3V

    #土壤湿度:干
    if 0 <= V <= 1.1:
        with canvas(device) as draw:
            draw.text((0, 0), '01Studio', fill="white")
            draw.text((0, 15), 'Soil_humidity test:', fill="white")
            draw.text((0, 40), str("%.2f" % V) + 'V' + ' Dry', fill="white")
        print("%.2f" % V + 'V' + ' Dry')

    #土壤湿度:中
    if 1.1 < V <= 2.2:
#onboard IoT board.
# Capacitive Soil Moisture Sensor v1.2 
# AliExpress https://bit.ly/3dMIDjD
from gpiozero import MCP3004,LED
from time import sleep

Vref = 3.3

adc = MCP3004(channel=0,device=1)
SensorPower0=LED(20)
SensorPower0.on()

while True:
	SensorPower0.on()
	print(adc.value*1000)
	SensorPower0.off()
	sleep(0.2)
Ejemplo n.º 7
0
#!/usr/bin/python

# Simple example of reading the MCP3008 analog input channels and printing them all out.

import time
from gpiozero import MCP3004

print('Reading MCP3004 values, press Ctrl-C to quit...')
print('| {0:>5} | {1:>5} | {2:>5} | {3:>5} |'.format(*range(4)))
print('-' * 32)

# Main program loop.
try:
    while True:
        # Read all the ADC channel values in a list.
        values = [0] * 4
        for i in range(4):
            # The read_adc function will get the value of the specified channel (0-7).
            values[i] = MCP3004(channel=i)
            print("Kanaal " + str(i) + ":" + str(MCP3004(channel=i).value))
# Print the ADC values.
#print('| {0:4.3f} | {1:4.3f} | {2:4.3f} | {3:4.3f} |'.format(*values))
# Pause for 3 seconds.
        time.sleep(3)

except KeyboardInterrupt:
    print('\nProgram terminated by keyboard interrupt: Ctrl-C')