#!/usr/bin/env python

# ADAPTER FROM:
# Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
# Copyright (c) 2014 Intel Corporation.
#
# By Fernando Osorio (FOsorio) - June 2015

import mraa
import time
import sys

# PWM Pin3 (Arduino)
x = mraa.Pwm(3)
x.period_ms(20)
x.enable(True)
## Read angle from Line Command Parameter
value1= int(sys.argv[1])
## Set PWM Value (Magic Value)
value = 0.025+(value1+90)*0.0007556

#while True:
x.write(value)
time.sleep(0.05)
x.write(value)
time.sleep(0.05)
##
## Repeat 2 or 3 time to be sure 
## to get the final angle
##
## x.write(value)
## time.sleep(0.05)
## x.write(value)
## time.sleep(0.05)


