LED on/off

This line produces PWM sine to PBA 7, how to make it turn on the LED at C13 when the sine is positive and turn it off when the sinus is negative?

val2 = 50 + amp / 10.0 * sin (stp * i + shift * 0.1 * 6.2831 / 360);

This line produces PWM sine to PBA 7,

No it doesn't.

Please remember to use code tags when posting code

This code will turn on LED on pin 13 on positive period and turn off LED on negative period.
Hope it helps.

#include <Arduino.h>
 
int led = 13;
float wave = 0;
int step = 0; // 0 - 360 degrees
bool led13 = false; // Value of LED ON/OFF

void setup() {                
  pinMode(led, OUTPUT);     
}

// the loop routine runs over and over again forever:
void loop() {
  // Calculate sine value of 
  wave = sin(step * DEG_TO_RAD);

  // Turn on LED on first step of positive period
  if (wave > 0 && !led13)
  {
    digitalWrite(led, HIGH);
    led13 = true;
  }
  // Turn off LED on first step of negative period
  else if (wave < 0 && led13)
  {
    digitalWrite(led, LOW);
    led13 = false;
  }

  // Reset step
  if (step++ > 360)
  {
    step = 0;
  }

  delay(5);
}

/Mogens

ted:
This line produces PWM sine to PBA 7, how to make it turn on the LED at C13 when the sine is positive and turn it off when the sinus is negative?

val2 = 50 + amp / 10.0 * sin (stp * i + shift * 0.1 * 6.2831 / 360);
[/quote]
What are you talking about?
What is the application?
What model Arduino?
Can you tell us your electronics, programming, Arduino, hardware experience?
Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.
Thanks.. Tom... :slight_smile:

how to make it turn on the LED at C13 when the sine is positive and turn it off when the sinus is negative?

The sin() function returns a value. Store that value in a variable.

 if(variable > 0)
    digitalWrite(C13, HIGH);
 else
    digitalWrite(C13, LOW);

Really, it's about as simple as it gets.