ITEAD OS BETA version only provides functions of UART, GPIO, PWM, and TIME for testing, as we have introduced functions UART and GPIO, here I'll show you how to use function PWM in ITEAD OS SDK.
First, let’s use pwm function to achieve a breathing light effect. To start, create a file breathing.c, then write the control code, using function analogWrite() to control brightness of LED lights from bright to dark and then from dark to bright repeatedly and to achieve a breathing light effect:
#include
int i;
int main()
{
while(1)
{
for (i=0;i<255;i++)
{
analogWrite(17,i);
delay(5);
}
for (i=255;i>0;i--)
{
analogWrite(17,i);
delay(5);
}
}
}
After saving the file, as described previously in other functions, use function iteadcompile to complie and generate an executable file directly, then use sudo command to run the file, and you can see the effect as in the video.
Then I’ll demonstrate how to control the brightness of LED light in Python through GUI interface and PWM function. Still, we need to create a file Pwm.py, write code in the file and a drag bar will be genarated in the graphical interface, and then we can control the brightness of LED light by dragging the bar with the mouse:
from ctypes import *
from Tkinter import *
def pwm(ev=None):
clib.analogWrite(c_int(17),c_int(scale.get()))
print scale.get()
clib=cdll.LoadLibrary("/usr/local/lib/libiteadIO.so")
root=Tk()
scale=Scale(root,from_=0,to=255,resolution=1,orient=HORIZONTAL,command=pwm)
scale.pack()
root.mainloop()
Using PWM function, we can also control other equipments such as stepper motor, servos, etc. When it works with the stepper motor shield – Motor Plug which will be released soon, we can make a DIY 3D printer or CNC engraving machine.
That’s all about the underlying application examples of the interfaces. Next, we will demonstrate functions for some modules in ITEAD OS SDK, such as reading RFID card directly through NFC module and displaying CPU occupancy rate, etc. on 128×64 OLED screen by using the display command – these functions that were not provided in BETA version will be developed and released in the official 1.0 version together with detailed documentations in the future.