GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( a3394c...b99246 )
by Virantha
01:31
created

boost_wedo_sensors   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 43
dl 0
loc 63
rs 10
c 0
b 0
f 0
wmc 8

1 Function

Rating   Name   Duplication   Size   Complexity  
A system() 0 2 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A Robot.tilt_sensor_change() 0 10 4
A Robot.motion_sensor_change() 0 3 1
A Robot.run() 0 15 2
1
import logging, struct
2
3
from curio import sleep, Queue
4
from bricknil import attach, start
5
from bricknil.hub import BoostHub
6
from bricknil.sensor import LED, ExternalMotionSensor, ExternalTiltSensor, WedoMotor
7
from bricknil.process import Process
8
from bricknil.const import Color
9
10
11
tilt_cap = ExternalTiltSensor.capability.sense_impact
12
motion_cap = ExternalMotionSensor.capability.sense_distance
13
14
@attach(LED, name='led') 
15
@attach(ExternalTiltSensor, name='tilt_sensor', capabilities=[tilt_cap])
16
@attach(WedoMotor, name='motor')
17
#@attach(ExternalMotionSensor, name='motion_sensor', capabilities=[motion_cap])
18
#@@attach(ExternalMotor, name='motor')
19
class Robot(BoostHub):
20
    """ Rotate the external motor connected to a boost hub by degrees
21
22
        Demonstrate both the absolute positioning as well as relative rotation.
23
    """
24
25
    async def motion_sensor_change(self):
26
        new_value = self.motion_sensor.value[motion_cap]
27
        print(f'motion sensor changed {new_value}')
28
29
    async def tilt_sensor_change(self):
30
        new_value = self.tilt_sensor.value[tilt_cap]
31
        if tilt_cap == ExternalTiltSensor.capability.sense_angle:
32
            x_angle = new_value[0]
33
            y_angle = new_value[1]
34
            print(f'tilt sensor changed {x_angle}, {y_angle}')
35
        elif tilt_cap == ExternalTiltSensor.capability.sense_orientation:
36
            print(f'orientation {new_value}')
37
        elif tilt_cap == ExternalTiltSensor.capability.sense_impact:
38
            print(f'impacts {new_value}')
39
40
    async def run(self):
41
        self.message("Running")
42
43
        # Set the robot LED to green to show we're ready
44
        await self.led.set_color(Color.green)
45
        await sleep(2)
46
47
48
        while True:
49
            await self.led.set_color(Color.blue)
50
            await self.motor.ramp_speed(50, 2000)
51
            await sleep(3)
52
            await self.led.set_color(Color.white)
53
            await self.motor.ramp_speed(-50, 2000)
54
            await sleep(3)
55
56
57
async def system():
58
    robot = Robot('Vernie')
59
    
60
if __name__ == '__main__':
61
    logging.basicConfig(level=logging.INFO)
62
    start(system)
63