Electrónica y Programación en Personal
«Si no se soluciona con un script en Python entonces no es viable»

por Yeison Cardona el 11 de mayo de 2012 a las 12:14 UTC

Extensiones comunes.rb, .rbw
Paradigmamultiparadigma: orientado a objetos, reflexivo
Apareció en1995
Diseñado porYukihiro Matsumoto
Última versión estable1.9.3
Tipo de datofuertemente tipado,dinámico
ImplementacionesRuby MRI, YARV,JRuby, Rubinius,IronRuby, MacRuby,HotRuby
Influido porPerl, Smalltalk, Python,Lisp, Eiffel, Scheme, Ada,Dylan, CLU
Ha influido aGroovy, Falcon
Sistema operativoMultiplataforma




*Tomado de Wikipedia



Código en Pinguino:
Seleccionar la arquitectura de su tarjeta Pinguino:
Éste código es el visto en éste post.
/*-----------------------------------------------------
Author:  Yeison Cardona --
First release: 05/03/2012
Last release: 11/05/2012
Description: Control de la tarjeta pinguino mediante
comandos transparentes enviados por CDC.
-----------------------------------------------------*/

#include 
#include 
#define TotalPines 17
 
char lectura[21], *bloque;
int par1, valor, cont, i;
 
void setup() {
 }

void leer_cadena() {
    unsigned char valor_leido[21];
    unsigned char receivedbyte;
    int cont=1;
    while (cont){    
        receivedbyte=CDC.read(valor_leido);
        valor_leido[receivedbyte]=0;
        if (receivedbyte>0) cont=0;}
    strcpy(lectura,valor_leido);}
  
void loop() {
 
leer_cadena();
cont=0;
 
if (strncmp(lectura, "pinMode", 7)==0){
 for (bloque = strtok(lectura,"("); bloque != NULL; bloque = strtok(NULL, ",") ){ 
 switch (cont){
 case 0: break;
 case 1:
  par1=atoi(bloque);
  break;
 case 2:
  if (strncmp(bloque, "INPUT", 5)==0) pinMode(par1,INPUT);
  else if (strncmp(bloque, "OUTPUT", 6)==0) pinMode(par1,OUTPUT);
  break;
 } 
 cont+=1;
 }
}
 
else if (strncmp(lectura, "digitalWrite", 12)==0){
 for (bloque = strtok(lectura,"("); bloque != NULL; bloque = strtok(NULL, ",") ){
 switch (cont){
 case 0: break;
 case 1:
  par1=atoi(bloque);
  break;
 case 2:
  if (strncmp(bloque, "HIGH", 4)==0) digitalWrite(par1,HIGH);
  else if (strncmp(bloque, "LOW", 3)==0) digitalWrite(par1,LOW);
  break;
 } 
 cont+=1;
 }
}
 
else if (strncmp(lectura, "analogWrite", 11)==0){
 for (bloque = strtok(lectura,"("); bloque != NULL; bloque = strtok(NULL, ",") ){
 switch (cont){
 case 0: break;
 case 1:
  par1=atoi(bloque);
  break;
 case 2:
  analogWrite(par1,atoi(bloque));
  break;
 } 
 cont+=1;
 }
}
 
else if (strncmp(lectura, "digitalRead", 11)==0){
 for (bloque = strtok(lectura,"("); bloque != NULL; bloque = strtok(NULL, ")") ){
 switch (cont){
 case 0: break;
 case 1:
  CDC.printf("%d\n",digitalRead(atoi(bloque)));
  break;
 } 
 cont+=1;
 }
}
 
else if (strncmp(lectura, "analogRead", 10)==0){
 for (bloque = strtok(lectura,"("); bloque != NULL; bloque = strtok(NULL, ")") ){
 switch (cont){
 case 0: break;
 case 1:
  CDC.printf("%d\n",analogRead(atoi(bloque)));
  break;
 } 
 cont+=1;
 }
}

else if (strncmp(lectura, "eepromRead", 10)==0){
 for (bloque = strtok(lectura,"("); bloque != NULL; bloque = strtok(NULL, ")") ){
 switch (cont){
 case 0: break;
 case 1:
  CDC.printf("%d\n",EEPROM.read(atoi(bloque)));
  break;
 } 
 cont+=1;
 }
}

else if (strncmp(lectura, "eepromWrite", 11)==0){
 for (bloque = strtok(lectura,"("); bloque != NULL; bloque = strtok(NULL, ",") ){
 switch (cont){
 case 0: break;
 case 1:
  par1=atoi(bloque);
  break;
 case 2:
  bloque = strtok(bloque,")");
  EEPROM.write(par1, atoi(bloque));
  break;
 } 
 cont+=1;
 }
}

else if (strncmp(lectura, "delay", 5)==0){
 for (bloque = strtok(lectura,"("); bloque != NULL; bloque = strtok(NULL, ")") ){
 switch (cont){
 case 0: break;
 case 1:
  delay(atoi(bloque));
  break;
 } 
 cont+=1;
 }
}
  
else if (strncmp(lectura, "delayMicroseconds", 17)==0){
 for (bloque = strtok(lectura,"("); bloque != NULL; bloque = strtok(NULL, ")") ){
 switch (cont){
 case 0: break;
 case 1:
  delayMicroseconds(atoi(bloque));
  CDC.printf("Done\n");
  break;
 } 
 cont+=1;
 }
}
  
else if (strcmp(lectura, "allOutput")==0){
 for (i=0;i<=TotalPines;i++){
  pinMode(i,OUTPUT);
  digitalWrite(i,LOW);
 }
}

else if (strcmp(lectura, "allInput")==0){
 for (i=0;i<=TotalPines;i++)
  pinMode(i,INPUT);
}

else if (strcmp(lectura, "allHigh")==0){
 for (i=0;i<=TotalPines;i++){
  pinMode(i,OUTPUT);
  digitalWrite(i,HIGH);
 }
}

else if (strcmp(lectura, "allLow")==0){
 for (i=0;i<=TotalPines;i++){
  pinMode(i,OUTPUT);
  digitalWrite(i,LOW);
 }
}
  
else if (strcmp(lectura, "reset")==0)
 reset();
  
}
/*-----------------------------------------------------
Author:  Yeison Cardona --
First release: 05/03/2012
Last release: 11/05/2012
Description: Control de la tarjeta pinguino mediante
comandos transparentes enviados por CDC.
-----------------------------------------------------*/
 
char lectura[21], *bloque;
int par1, valor, cont, i;
 
#include 
#include 
#define TotalPines 21
 
void setup() {
 }

void leer_cadena() {
    unsigned char valor_leido[21];
    unsigned char receivedbyte;
    int cont=1;
    while (cont){    
        receivedbyte=CDC.read(valor_leido);
        valor_leido[receivedbyte]=0;
        if (receivedbyte>0) cont=0;}
    strcpy(lectura,valor_leido);}
  
void loop() {
 
leer_cadena();
cont=0;
 
if (strncmp(lectura, "pinMode", 7)==0){
 for (bloque = strtok(lectura,"("); bloque != NULL; bloque = strtok(NULL, ",") ){ 
 switch (cont){
 case 0: break;
 case 1:
  par1=atoi(bloque);
  break;
 case 2:
  if (strncmp(bloque, "INPUT", 5)==0) pinMode(par1,INPUT);
  else if (strncmp(bloque, "OUTPUT", 6)==0) pinMode(par1,OUTPUT);
  break;
 } 
 cont+=1;
 }
}
 
else if (strncmp(lectura, "digitalWrite", 12)==0){
 for (bloque = strtok(lectura,"("); bloque != NULL; bloque = strtok(NULL, ",") ){
 switch (cont){
 case 0: break;
 case 1:
  par1=atoi(bloque);
  break;
 case 2:
  if (strncmp(bloque, "HIGH", 4)==0) digitalWrite(par1,HIGH);
  else if (strncmp(bloque, "LOW", 3)==0) digitalWrite(par1,LOW);
  break;
 } 
 cont+=1;
 }
}
 
else if (strncmp(lectura, "analogWrite", 11)==0){
 for (bloque = strtok(lectura,"("); bloque != NULL; bloque = strtok(NULL, ",") ){
 switch (cont){
 case 0: break;
 case 1:
  par1=atoi(bloque);
  break;
 case 2:
  analogWrite(par1,atoi(bloque));
  break;
 } 
 cont+=1;
 }
}
 
else if (strncmp(lectura, "digitalRead", 11)==0){
 for (bloque = strtok(lectura,"("); bloque != NULL; bloque = strtok(NULL, ")") ){
 switch (cont){
 case 0: break;
 case 1:
  CDC.printf("%d\n",digitalRead(atoi(bloque)));
  break;
 } 
 cont+=1;
 }
}
 
else if (strncmp(lectura, "analogRead", 10)==0){
 for (bloque = strtok(lectura,"("); bloque != NULL; bloque = strtok(NULL, ")") ){
 switch (cont){
 case 0: break;
 case 1:
  CDC.printf("%d\n",analogRead(atoi(bloque)));
  break;
 } 
 cont+=1;
 }
}

else if (strncmp(lectura, "delay", 5)==0){
 for (bloque = strtok(lectura,"("); bloque != NULL; bloque = strtok(NULL, ")") ){
 switch (cont){
 case 0: break;
 case 1:
  delay(atoi(bloque));
  break;
 } 
 cont+=1;
 }
}
  
else if (strncmp(lectura, "delayMicroseconds", 17)==0){
 for (bloque = strtok(lectura,"("); bloque != NULL; bloque = strtok(NULL, ")") ){
 switch (cont){
 case 0: break;
 case 1:
  delayMicroseconds(atoi(bloque));
  CDC.printf("Done\n");
  break;
 } 
 cont+=1;
 }
}
  
else if (strcmp(lectura, "allOutput")==0){
 for (i=0;i<=TotalPines;i++){
  pinMode(i,OUTPUT);
  digitalWrite(i,LOW);
 }
}

else if (strcmp(lectura, "allInput")==0){
 for (i=0;i<=TotalPines;i++)
  pinMode(i,INPUT);
}

else if (strcmp(lectura, "allHigh")==0){
 for (i=0;i<=TotalPines;i++){
  pinMode(i,OUTPUT);
  digitalWrite(i,HIGH);
 }
}

else if (strcmp(lectura, "allLow")==0){
 for (i=0;i<=TotalPines;i++){
  pinMode(i,OUTPUT);
  digitalWrite(i,LOW);
 }
}
  
}
Script en Ruby: Simple ejemplo de "blinkLED" usando una interfaz con Ruby. Dependencias:
sudo apt­-get install ruby-serialport
Script:
#!/usr/bin/env ruby

#Importamos el módulo serial
require 'serialport' 
   
port_str = "/dev/ttyACM0" #El puerto puede variar
baud_rate = 9600  
data_bits = 8  
stop_bits = 1  
parity = SerialPort::NONE  
  
pinguino = SerialPort.new(port_str, baud_rate, data_bits, stop_bits, parity)  
 
pinguino.write "pinMode(13,OUTPUT)"
while true do  
    pinguino.write "digitalWrite(13,HIGH)" 
    sleep(0.25) 
    pinguino.write "digitalWrite(13,LOW)" 
    sleep(0.25)
end 



>>Otros Lenguajes de Programación

También podría interesarte:

Comentarios:
wuiutffzjwn dijo:
dic. 8, 2013, 9:43 p.m.
FpEuEh zfzvrvychucx, [url=http://xinqaxryqmol.com/]xinqaxryqmol[/url], [link=http://jsyilbbieebj.com/]jsyilbbieebj[/link], http://heirsxbpnszy.com/
Responder a wuiutffzjwn
Añadir un nuevo comentario:
Si desean una respuesta para su comentario sólo deben agregarme en G+ y hacer una mención a Yeison Cardona, así les podré responder lo antes posible.