Counter

Hello Forum
I want to build a counter with the brickpi. I need it for my robot. When i press the touch sensor, it shold stand still. If i press again, it starts again. Who can help me? Thanks

Hello Modulok,
Not sure anyone can build you that specific thing. But if you want to make something and need help with a coding issue, we can certainly hop in and help out!
John

this is my solution, but with a secon button to stop the robot.


#!/usr/bin/env python
from BrickPi import *
BrickPiSetup()
BrickPi.MotorEnable[PORT_A] = 1
BrickPi.MotorEnable[PORT_D] = 1
BrickPi.SensorType[PORT_4] = TYPE_SENSOR_ULTRASONIC_CONT
BrickPi.SensorType[PORT_1] = TYPE_SENSOR_TOUCH
BrickPi.SensorType[PORT_3] = TYPE_SENSOR_TOUCH
BrickPiSetupSensors()
BrickPiUpdateValues()
def start():
    running = True
    while running:
        if BrickPi.Sensor[PORT_3]:
            stop()
            return stop()
        if BrickPi.Sensor[PORT_4] < 30 :
            BrickPi.MotorSpeed[PORT_A] = -200
            BrickPi.MotorSpeed[PORT_D] = 200
            ot = time.time()
            while(time.time() - ot < 0.5):
                BrickPiUpdateValues()
                time.sleep(.2)
        else:
            BrickPiUpdateValues()
            BrickPi.MotorSpeed[PORT_A] = 200
            BrickPi.MotorSpeed[PORT_D] = 200
            time.sleep(.2)
def stop():
    BrickPi.MotorSpeed[PORT_A] = 0
    BrickPi.MotorSpeed[PORT_D] = 0
while True :
    BrickPiUpdateValues()
    if BrickPi.Sensor[PORT_1]:
        start()
    time.sleep(.2)