BEST GPIO PWM I2C UART library (Linux)
(no dependencies)
SAMPLE CLOCK ON OLED 96 DISPLAY
// clock
oled := Oled96(11, 0x3c, "OLED96");
oled.autoopen(false);
function main(a)
{
if(oled.xopen("128x64",0,0))
{
oled.clear_display(0);
k = run(program, 1000);
}
oled.xclose();
return k;
}
function program(ctx,dev)
{
oled.write_string(0,1, get_strtime() ,2);
return true;
}
GPIO CONTROL
int i;
b := PIO(506, DIR_IN, PULL_HIGH, "button");
l := PIO(507, DIR_OUT, LOW, "led");
function main(ctx)
{
b.set_monitor(true);
return run(loop,-1);
}
function loop(ctx, dev)
{
if(dev){
if(0 == dev.get_value(/*this is the monitored button*/))
l.toggle();
}
return true;
}
PWM CONTROL
int i;
var pwm = PWM("0.0", 1000, 100, false, "pwm");
var k = 0;
function main(ctx)
{
return run(loop,10);
}
function loop(ctx, dev)
{
pwm.set_value(k++);
return true;
}
EVEN ARDUINO STYLE :)
::import("./modules/libardulike.so");
var LED=26;
function main(x)
{
wiringPiSetupGpio () ;
pinMode (LED, OUTPUT) ;
for (;;)
{
digitalWrite (LED, 1) ; // On
delay (500) ; // mS
digitalWrite (LED, 0) ; // Off
delay (500) ;
}
}
GOING FANCY..
::using(eSOLIB);
lib := LIB("libglfw.so");
lib2 := LIB("libGL.so.1.0.0");
GL_COLOR_BUFFER_BIT := 0x00004000
lib.load("glfwInit",true,0);
lib.load("glfwCreateWindow",true,5);
lib.load("glfwMakeContextCurrent",false,1);
lib.load("glfwWindowShouldClose",true,1);
lib.load("glfwSwapBuffers",false,1);
lib.load("glfwPollEvents",false,0);
lib.load("glfwTerminate",false,0);
lib2.load("glClear",0,1);
function main(x)
{
var ii = glfwInit();
var window = glfwCreateWindow(640, 480, "Hello World", null, null);
if (window==null)
{
println("---------iit terminated ");
glfwTerminate();
return false;
}
glfwMakeContextCurrent(window);
while (!glfwWindowShouldClose(window))
{
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwTerminate();
return false;
}
GITHUB:https://github.com/comarius/amutrion/