from machine import Pin

class WindVane:
    def __init__(self, p12, p13, p14, p15):
        # IR Sensors (Pull-up means 1 = Open, 0 = Triggered)
        self.n = Pin(p12, Pin.IN, Pin.PULL_UP)
        self.e = Pin(p13, Pin.IN, Pin.PULL_UP)
        self.s = Pin(p14, Pin.IN, Pin.PULL_UP)
        self.w = Pin(p15, Pin.IN, Pin.PULL_UP)

    def get_direction(self):
        # Read and invert (so True means the sensor is active)
        n_on = not self.n.value()
        e_on = not self.e.value()
        s_on = not self.s.value()
        w_on = not self.w.value()

        # Check Diagonals first
        if n_on and e_on: return "North-East"
        if s_on and e_on: return "South-East"
        if s_on and w_on: return "South-West"
        if n_on and w_on: return "North-West"

        # Check Cardinals
        if n_on: return "North"
        if e_on: return "East"
        if s_on: return "South"
        if w_on: return "West"
        
        return "Calm"