import network
import espnow
import time
from machine import ADC, Pin
import ujson

wlan = network.WLAN(network.STA_IF)
wlan.active(True)

e = espnow.ESPNow()
e.active(True)

peer = b'bla bla bla'  # change this to your helicopter Mac Addr
e.add_peer(peer)



adc_x = ADC(Pin(14))  # VRx
adc_x.atten(ADC.ATTN_11DB)  # Full range: 0-3.3V
adc_x.width(ADC.WIDTH_12BIT)  # 0-4095

adc_y = ADC(Pin(13))  # VRy
adc_y.atten(ADC.ATTN_11DB)
adc_y.width(ADC.WIDTH_12BIT)

adc_1x = ADC(Pin(11))  # VRx
adc_1x.atten(ADC.ATTN_11DB)  # Full range: 0-3.3V
adc_1x.width(ADC.WIDTH_12BIT)  # 0-4095

adc_1y = ADC(Pin(12))  # VRy
adc_1y.atten(ADC.ATTN_11DB)
adc_1y.width(ADC.WIDTH_12BIT)

pot = ADC(Pin(10))            # ADC pin
pot.atten(ADC.ATTN_11DB)     # 0–3.3V

while True:
    x = adc_x.read()  # 0-4095
    y = adc_y.read()  # 0-4095
    x1 = adc_1x.read()  # 0-4095
    y1 = adc_1y.read()  # 0-4095
    
    value = pot.read()
    print(value/4095)
    
    print("X:", x, "Y:", y)
    print("X1:", x1, "Y1:", y1)
    
    data = [x,y,x1,y1,value,value]
    msg = ujson.dumps(data).encode()
    e.send(peer, msg)
    time.sleep(0.1)
    