JavaScript is required to view this page.
Skip to content
Get 50% OFF 2x Smart Devices with your HA Yellow Kit + CM4
Get 50% OFF 2x Smart Devices with your HA Yellow Kit + CM4
Coding: "Red" Language Introduces Integrated GPIO Support

Coding: "Red" Language Introduces Integrated GPIO Support

Here at ameriDroid, we're fans of the Red programming language. Red is a full-stack language. "Full-stack" means that the language excels at writing low-level code (like hardware drivers and operating system kernels) as well as the highest-level code (like Domain Specific Languages, macros, applications, etc.).

Red is a highly expressive language that also generates very efficient and compact code.

This is a great benefit to the single-board computer software developer as many SBC applications are combined with hardware-level access and control. With almost every other language (i.e. Python), a third-party library (i.e. wiringPi) needs to be added to provide GPIO access.

Check out this demo of GPIO integrated into the language:

Here's an example of all the code required to turn pin 4 to an "on" state:

port: open gpio://
insert port [set-mode 4 out]
repeat [
insert port [set 4 odd? now/time]
wait 1
]
close port

This sets pin 4 to be an output pin and then turns pin 4 on and off once per second.

Here's an example of the same functionality using wiringPi in C, after wiringPi has been downloaded and placed in the proper location on the development computer:

#include <wiringPi.h>
int main (void)
{
  wiringPiSetup () ;
  pinMode (4, OUTPUT) ;
  for (;;)
  {
    digitalWrite (4, HIGH) ; delay (1000) ;
    digitalWrite (4,  LOW) ; delay (1000) ;
  }
  return 0 ;
}

Now that the GPIO port functionality has been developed for Red, a DSL could be easily implemented that would allow the same functionality to be accomplished as simply as this:

do %gpio.red ;-- This loads the GPIO DSL
gpio [
p4: set 4 out on rate 1 [
p4/state: not p4/state
]
]

The prototype is being tested on the Raspberry Pi, but will work on most (if not all) SBCs in the future.

Read the full article here.

Previous article New Shelly Kits

Leave a comment

Comments must be approved before appearing

* Required fields

x