Exemplo n.º 1
0
    def instance_arduino_code(self, ad):
        ad.setup.add_call(Arduino.pinMode(self.signal_pin, Arduino.OUTPUT))

        ad.loop.add_call(
            self.cycletime.set(self.basic_board_module.current_time -
                               self.last_cycle),
            if_(
                self.cycletime > self.full_cycle,
                (
                    self.cycletime.set(0),
                    self.last_cycle.set(self.basic_board_module.current_time),
                ),
            ),
            if_(
                self.duty_cycle == 0,
                Arduino.digitalWrite(self.signal_pin, Arduino.HIGH),
            ),
            elseif_(
                self.duty_cycle == 100,
                Arduino.digitalWrite(self.signal_pin, Arduino.LOW),
            ),
            elseif_(
                self.cycletime < self.full_cycle *
                ((self.duty_cycle.cast(float_) / self.duty_cycle.maximum)),
                Arduino.digitalWrite(self.signal_pin, Arduino.LOW),
            ),
            else_(Arduino.digitalWrite(self.signal_pin, Arduino.HIGH)),
        )

        self.signal_pin.arduino_setter.add_call(
            Arduino.pinMode(self.signal_pin, Arduino.OUTPUT))
Exemplo n.º 2
0
 def instance_arduino_code(self, ad):
     ad.setup.add_call(Arduino.pinMode(self.relay_pin, Arduino.OUTPUT))
     ad.loop.add_call(
         if_(self.active, Arduino.digitalWrite(self.relay_pin, Arduino.LOW)),
         else_(Arduino.digitalWrite(self.relay_pin, Arduino.HIGH)),
     )
     self.relay_pin.arduino_setter.add_call(
         Arduino.pinMode(self.relay_pin, Arduino.OUTPUT)
     )
Exemplo n.º 3
0
class PushButtoModule(ArduinoBoardModule):
    # depencies
    basic_board_module = BasicBoardModule

    # arduino_variables
    button_pin = arduio_variable(name="button_pin",
                                 arduino_data_type=uint8_t,
                                 eeprom=True)
    button_pressed = arduio_variable(
        name="button_pressed",
        arduino_data_type=bool_,
        setter=False,
        arduio_setter=False,
        is_data_point=True,
    )
    reinitalize_button = at.Function("reinitalize_button", uint8_t)
    reinitalize_button.add_call(
        Arduino.pinMode(reinitalize_button.arg1, Arduino.INPUT))

    def instance_arduino_code(self, ad):
        ad.setup.add_call(self.reinitalize_button(self.button_pin))
        self.button_pin.arduino_setter.add_call(
            self.reinitalize_button(self.button_pin))

        ad.loop.add_call(
            if_(
                Arduino.digitalRead(self.button_pin) == Arduino.HIGH,
                self.button_pressed.set(Arduino.true),
            ),
            else_(self.button_pressed.set(Arduino.false)),
        )
Exemplo n.º 4
0
    def instance_arduino_code(self, ad):
        ad.setup.add_call(Arduino.pinMode(self.relay_pin, Arduino.OUTPUT))

        ad.loop.add_call(
            self.cycletime.set(self.basic_board_module.current_time - self.last_cycle),
            if_(self.cycletime > self.full_cycle, self.cycletime.set(0)),
            if_(
                self.cycletime > self.full_cycle * self.duty_cycle,
                Arduino.digitalWrite(self.relay_pin, Arduino.HIGH),
            ),
            else_(Arduino.digitalWrite(self.relay_pin, Arduino.HIGH)),
        )

        self.relay_pin.arduino_setter.add_call(
            Arduino.pinMode(self.relay_pin, Arduino.OUTPUT)
        )
Exemplo n.º 5
0
    def add_arduino_code(self, ad):
        ad.loop.add_call(
            Arduino.analogWrite(self.red_pin, self.red),
            Arduino.analogWrite(self.green_pin, self.green),
            Arduino.analogWrite(self.blue_pin, self.blue),
        )

        self.blue_pin.arduino_setter.prepend_call(
            Arduino.analogWrite(self.blue_pin, 0))
        self.blue_pin.arduino_setter.add_call(
            Arduino.pinMode(self.blue_pin, Arduino.OUTPUT))

        self.red_pin.arduino_setter.prepend_call(
            Arduino.analogWrite(self.red_pin, 0))
        self.red_pin.arduino_setter.add_call(
            Arduino.pinMode(self.red_pin, Arduino.OUTPUT))

        self.green_pin.arduino_setter.prepend_call(
            Arduino.analogWrite(self.green_pin, 0))
        self.green_pin.arduino_setter.add_call(
            Arduino.pinMode(self.green_pin, Arduino.OUTPUT))
Exemplo n.º 6
0
    def add_arduino_code(self, ad):

        ad.loop.add_call(
            self.avg.set(0),
            for_(
                for_.i,
                for_.i < self.samples,
                1,
                self.avg.set(self.avg + Arduino.analogRead(self.analog_pin2)),
            ),
            self.analog_value2.set(self.avg / self.samples),
        )

        self.analog_pin2.arduino_setter.add_call(
            Arduino.pinMode(self.analog_pin2, Arduino.INPUT))
Exemplo n.º 7
0
    def module_arduino_code(cls, board, arduino_code_creator):
        cls.deactivate_pin.add_call(
            if_(
                cls.active_cs_pin > 0,
                code=(
                    Arduino.digitalWrite(cls.active_cs_pin, Arduino.HIGH),
                    cls.active_cs_pin.set(0),
                ),
            )
        )

        cls.activate_pin.add_call(
            if_(cls.active_cs_pin == cls.activate_pin.arg1, return_()),
            if_(cls.active_cs_pin > 0, cls.deactivate_pin()),
            Arduino.pinMode(cls.activate_pin.arg1, Arduino.OUTPUT),
            cls.active_cs_pin.set(cls.activate_pin.arg1),
            Arduino.digitalWrite(cls.active_cs_pin, Arduino.LOW),
        )
Exemplo n.º 8
0
    def add_arduino_code(self, ad):

        ad.setup.add_call(Arduino.analogReference(Arduino.EXTERNAL))

        ad.loop.add_call(
            self.avg.set(0),
            for_(
                for_.i,
                for_.i < self.samples,
                1,
                self.avg.set(self.avg + Arduino.analogRead(self.analog_pin)),
            ),
            self.analog_value.set(self.avg / self.samples),
        )

        self.analog_pin.arduino_setter.add_call(
            Arduino.pinMode(self.analog_pin, Arduino.INPUT)
        )
Exemplo n.º 9
0
 def add_arduino_code(self, ad):
     ad.setup.add_call(Arduino.pinMode(self.relay_pin, Arduino.OUTPUT))
     ad.loop.add_call(Arduino.digitalWrite(self.relay_pin, self.open))
     self.relay_pin.arduino_setter.add_call(
         Arduino.pinMode(self.relay_pin, Arduino.OUTPUT))