Problem with porting Arduino sketch to WiringPi - Raspberry Pi Forums


i want make rather simple arduino sketch work on raspberry pi using wiringpi libary gordon.
on arduino uno sending infrared signals tv.
nothing more little advanced led blinking guess i'm keep failing port c/wiringpi syntax. i'm little familiar c++ not c, here appreciated.

note, c code compiling fine instant exiting when run , doesn't print test message.

arduino sketch:
const int irledpin = 13;
const int buttonpin = 2;
const int dm = 520;

int buttonstate = 0;

void setup() {
  pinmode(irledpin, output);
  pinmode(buttonpin, input);
  serial.begin(9600);
}
 
void loop()
{
  buttonstate = digitalread(buttonpin);
  delay(10);
  if (buttonstate == high) {
  //serial.println("sending ir signal");
  sendsleepcode();
  sendvolumeupcode();
  sendvolumedowncode();
   }
}
 
// this procedure sends a 38khz pulse to the irledpin 
// for a certain # of microseconds. we'll use this whenever we need to send codes
void pulseir(long microsecs) {
  // we'll count down number of microseconds told wait
 
  cli();  // turns off background interrupts
 
  while (microsecs > 0) {
    // 38 khz 13 microseconds high , 13 microseconds low
   digitalwrite(irledpin, high); // takes 3 microseconds happen
   delaymicroseconds(10); // hang out 10 microseconds
   digitalwrite(irledpin, low); // takes 3 microseconds
   delaymicroseconds(10); // hang out 10 microseconds
 
   // 26 microseconds altogether
   microsecs -= 26;
  }
 
  sei();  // turns them on
}
void endcode() {
small();
delaymicroseconds(dm); pulseir(1240);
smallpair();
smallpair();

void bigpair() {
delaymicroseconds(dm); pulseir(1240);
delaymicroseconds(dm); pulseir(1240);

void smallpair() {
small();
small();
}
void small() {
delaymicroseconds(dm); pulseir(1240);

void big() {
delaymicroseconds(dm); pulseir(640);

void sendsleepcode() {
for (int = 0; < 3; i++) {
delaymicroseconds(24600); pulseir(2440);
small();
bigpair();
small();
bigpair();
endcode();
}}
void sendvolumeupcode() {
for (int = 0; < 3; i++) {
delaymicroseconds(25780); pulseir(2440);
small();
delaymicroseconds(dm); pulseir(1240);
smallpair();
delaymicroseconds(dm); pulseir(1240);
small();
endcode();
}}
void sendvolumedowncode() {
for (int = 0; < 3; i++) {
big();
bigpair();
smallpair();
big();
small();
endcode();
}}
, simplified c file wiringpi. use 1 ir code testing.
#include <wiringpi.h>
#include <stdio.h>

const int irledpin = 7;
const int dm = 520;

void pulseir(long microsecs);
void small();
void big();

int main (void) {

pinmode(irledpin, output);

for (;;)
{
  delay(10);
   
  printf ("sending ir signal");
  //for (int = 0; < 3; i++) {
delaymicroseconds(25780); pulseir(2440);
small();
big();
small();
small();
big();
small();
small();
big();
small();
small();
small();
small();
//}
 }  
    // wait twenty seconds (20 seconds * 1000 milliseconds)


void pulseir(long microsecs) {
while (microsecs > 0) {
    // 38 khz 13 microseconds high , 13 microseconds low
   digitalwrite(irledpin, high); // takes 3 microseconds happen
   delaymicroseconds(10); // hang out 10 microseconds
   digitalwrite(irledpin, low); // takes 3 microseconds
   delaymicroseconds(10); // hang out 10 microseconds
   microsecs -= 26;
  }
}
void small() {
delaymicroseconds(dm); pulseir(1240);

void big() {
delaymicroseconds(dm); pulseir(640);

you must call 1 of wiringpi library initialisation functions.


raspberrypi



Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums