Please enable javascript, or click here to visit my ecommerce web site powered by Shopify.
Jump to: navigation, search

Rock/LED

< Rock
Revision as of 02:54, 20 May 2014 by Hipboi (Talk | contribs)

The RR has 3 LEDs, green(172), blue(174), red(175). All can be programmable.


Below is program in different languages to flash the green led on RR.

c

#include <stdio.h>

int main()
{
  FILE *fp = fopen("/sys/class/gpio/export", "w");
  if( !fp )
  {
    printf("error open export file");
    return 1;
  }
  fprintf(fp, "%d", 175);
  fclose(fp);

  fp = fopen("/sys/class/gpio/gpio175/direction", "w");

  if( !fp )
  {
    printf("error open export file");
    return 1;
  }
  fprintf(fp, "%s", "out");
  fclose(fp);

  fp = fopen("/sys/class/gpio/gpio175/value", "w");

  if( !fp )
  {
    printf("error open export file");
    return 1;
  }
  fprintf(fp, "%d", 1);
 
}

python

import time

def initpin(pinnum, mode):
  '''
  pinnum: pin number, eg. 172, 175 etc.
  mode: pin mode, valid values: in or out
  '''

  with open('/sys/class/gpio/export', 'w') as f:
    f.write(str(pinnum))

  with open('/sys/class/gpio/gpio' + str(pinnum) + '/direction', 'w') as f:
    f.write(str(mode))

def setpin(pinnum, value):
 
  with open('/sys/class/gpio/gpio' + str(pinnum) + '/value', 'w') as f:
    f.write(str(value))

if __name__ == '__main__':
  initpin(175, 'out')
  while True:
    setpin(175, 0)
    time.sleep(1)
    setpin(175, 1)
    time.sleep(1)

shell

#!/bin/sh

# enable the gpio 172 -> green led
echo 172 > /sys/class/gpio/export

# set the direction to output
echo "out" > /sys/class/gpio/gpio172/direction
while true;
do
echo 0 > /sys/class/gpio/gpio172/value #led on
sleep 1
echo 1 > /sys/class/gpio/gpio172/value #led off
sleep 1
done

LED class and triggers

on radxa-rock/android-kk branch, 3 LEDs are configured as LED class devices. you can control LEDs via /sys/class/leds/.