X-Git-Url: https://git.ayoreis.com/Adafruit_Blinka-hackapet.git/blobdiff_plain/4d339fcb18c46af2d579ca60971182f6f5f93768..e581ddf6e329e49b0c7c48c3c0ac967aa6a30571:/src/adafruit_blinka/microcontroller/generic_agnostic_board/pin.py diff --git a/src/adafruit_blinka/microcontroller/generic_agnostic_board/pin.py b/src/adafruit_blinka/microcontroller/generic_agnostic_board/pin.py index 9ad9905..c527759 100644 --- a/src/adafruit_blinka/microcontroller/generic_agnostic_board/pin.py +++ b/src/adafruit_blinka/microcontroller/generic_agnostic_board/pin.py @@ -4,7 +4,7 @@ """generic_agnostic_board pin interface""" import random -# Values for sine wave output +# Values for sine wave # (data points = 20, amplitude=100, frequency=1) sine_wave = [ 0, @@ -29,6 +29,31 @@ sine_wave = [ -31, ] +# Values for a sawtooth wave +# (data points = 20, amplitude=100) +sawtooth_wave = [ + -100, + -80, + -60, + -40, + -20, + 0, + 20, + 40, + 60, + 80, + -100, + -80, + -60, + -40, + -20, + 0, + 20, + 40, + 60, + 80, +] + class Pin: """A basic Pin class for use with generic_agnostic_board""" @@ -72,11 +97,17 @@ class Pin: if self._wave_idx is None: self._wave_idx = 0 else: - self._wave_idx += 1 - if self._wave_idx >= len(sine_wave): - self._wave_idx = 0 + self._wave_idx = (self._wave_idx + 1) % len(sine_wave) return sine_wave[self._wave_idx] + def return_sawtooth_wave(self): + """Returns the next value in the sawtooth wave""" + if self._wave_idx is None: + self._wave_idx = 0 + else: + self._wave_idx = (self._wave_idx + 1) % len(sawtooth_wave) + return sawtooth_wave[self._wave_idx] + def __init__(self, pin_id=None): self.id = pin_id self._mode = None @@ -92,13 +123,11 @@ class Pin: 2: self.return_true, # Dx_INPUT_TRUE_PULL_UP 3: self.return_true, # Dx_INPUT_TRUE_PULL_DOWN 4: self.return_true, # Dx_OUTPUT - 6: self.return_true, # NEOPIXEL 7: self.return_random_int, # Ax_INPUT_RAND_INT 8: self.return_fixed_int_pi, # Ax_INPUT_FIXED_INT_PI - 9: self.return_sine_wave, # Ax_OUTPUT_WAVE_SINE - 10: self.return_true, # Ax_OUTPUT_WAVE_SAWTOOTH + 9: self.return_sine_wave, # Ax_INPUT_WAVE_SINE + 10: self.return_sawtooth_wave, # Ax_INPUT_WAVE_SAW 11: self.return_toggle, # Dx_INPUT_TOGGLE - # Add other mappings as needed } def init(self, mode=IN, pull=None): @@ -149,8 +178,8 @@ class Pin: # Analog Out if self._mode == Pin.DAC: if val is None: - # write only - raise AttributeError("unreadable attribute") + self.previous_value = self.current_value + return self.current_value self.write(val) return None raise RuntimeError( @@ -171,6 +200,7 @@ A0 = Pin(7) A1 = Pin(8) A2 = Pin(9) A3 = Pin(10) +A4 = Pin(12) D7 = Pin(11)