Take the 2-minute tour ×
Raspberry Pi Stack Exchange is a question and answer site for users and developers of hardware and software for Raspberry Pi. It's 100% free, no registration required.

I have the code below I am trying to build

#include stdio.h
#include stdlib.h
#include signal.h
#include wiringPi.h
#include softPwm.h

void control_event(int sig);
int HARD_PWM_PIN=1; Hardware PWM Pin(GPIO18-12)
int SOFT_PWM_PIN=0; Software PWM Pin(GPIO0-11)
int DELAY_MS=10;
int main(void)
{
  (void)signal(SIGINT,control_event);
  (void)signal (SIGQUIT,control_event);
  printf(Hardware and software based PWM test on LEDn);
  if(getuid()!=0) wiringPi requires root privileges
  {
    printf(ErrorwiringPi must be run as root.n);
    return 1;
  }
  if(wiringPiSetup()==-1)
  {
    printf(ErrorwiringPi setup failed.n);
    return 1;
  }
  pinMode(HARD_PWM_PIN,PWM_OUTPUT); setup hardware pwm
  softPwmCreate(SOFT_PWM_PIN,0,100); setup software pwm pin
  int up;
  int down;
  while(1)
  {
    for(up=1;up=5;down--)
    {
      pwmWrite(HARD_PWM_PIN,down);
      softPwmWrite(SOFT_PWM_PIN,down);
      delay(DELAY_MS2);
    }
    delay(DELAY_MS5);
  }
}
void control_event(int sig)
{
  printf(bbExiting...n);
  pwmWrite(HARD_PWM_PIN,0);
  softPwmWrite(SOFT_PWM_PIN,0);
  delay(100); wait a little for the pwm to finish write
  exit(0);
}

But I keep getting the following errors this is only a portion of them but they are pretty much the same throughout with the odd symbols and numbers.

test1.c:20:1: error: stray â\302â in program
test1.c:20:1: error: stray â\240â in program
test1.c:21:1: error: stray â\302â in program
test1.c:21:1: error: stray â\240â in program
test1.c:22:1: error: stray â\302â in program
test1.c:22:1: error: stray â\240â in program
test1.c:23:1: error: stray â\302â in program
test1.c:23:1: error: stray â\240â in program
test1.c:23:1: error: stray â\302â in program
test1.c:23:1: error: stray â\240â in program
test1.c:24:1: error: stray â\302â in program
test1.c:24:1: error: stray â\240â in program
test1.c:24:1: error: stray â\302â in program
test1.c:24:1: error: stray â\240â in program
test1.c:25:1: error: stray â\302â in program
test1.c:25:1: error: stray â\240â in program
test1.c:26:1: error: stray â\302â in program
test1.c:26:1: error: stray â\240â in program
test1.c:26:38: error: unknown type name âsetupâ
test1.c:26:53: error: expected â=â, â,â, â;â, âasmâ or â__attribute__â before âpwmâ

What could be wrong?

share|improve this question
2  
The C-style string literals have the following form: "Exiting..." or {'E', 'x', 'i', 't', 'i', 'n', 'g', 0}. –  okertanov Feb 24 '13 at 9:10
2  
And comments are /* Wait a little... */ –  okertanov Feb 24 '13 at 9:12
add comment

1 Answer

up vote 3 down vote accepted

Like @okertanov said, your code has syntax errors. In C, comments must be enclosed /* like this */, strings for printf "have to be in quotes", and newlines are printed with \n inside the quotes.

Try something like this:

#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <wiringPi.h>
#include <softPwm.h>

void control_event(int sig);

int HARD_PWM_PIN=1; /* Hardware PWM Pin(GPIO18-12) */
int SOFT_PWM_PIN=0; /* Software PWM Pin(GPIO0-11) */
int DELAY_MS=10;

int main(void)
{
  (void)signal(SIGINT,control_event); /* this looks like a syntax error but I assume you know what you're doing */
  (void)signal (SIGQUIT,control_event);
  printf("Hardware and software based PWM test on LED\n");
  if(getuid()!=0) /* wiringPi requires root privileges */
  {
    printf("Error: wiringPi must be run as root\n");
    return 1;
  }
  if(wiringPiSetup()==-1)
  {
    printf("Error: wiringPi setup failed\n");
    return 1;
  }
  pinMode(HARD_PWM_PIN,PWM_OUTPUT); /* setup hardware pwm */
  softPwmCreate(SOFT_PWM_PIN,0,100); /* setup software pwm pin */
  int up;
  int down;
  while(1)
  {
    for(up=1;up=5;down--)
    {
      pwmWrite(HARD_PWM_PIN,down);
      softPwmWrite(SOFT_PWM_PIN,down);
      delay(DELAY_MS2);
    }
    delay(DELAY_MS5);
  }
}

void control_event(int sig)
{
  printf("Exiting...\n");
  pwmWrite(HARD_PWM_PIN,0);
  softPwmWrite(SOFT_PWM_PIN,0);
  delay(100); /* wait a little for the pwm to finish write */
  exit(0);
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.