Buona sera,
ho un problema e sono qui a chiedere aiuto.
Vorrei fare uno sketch che riceva codici da telecomandi IR, ma nel contempo possa generare un PWM sul pin D11.
Lo sketch allegato fa un ciclo faading sul led D11 tramite il pwm.
Succede che se abilito gli interrupt (tolgo // rigo 46) il PWM non funziona più.
Suggerimenti?
Molte grazie
/*
Fading
This example shows how to fade an LED using the analogWrite() function.
The circuit:
- LED attached from digital pin 9 to ground.
created 1 Nov 2008
by David A. Mellis
modified 30 Aug 2011
by Tom Igoe
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/Fading
*/
#include <IRremote.h>
#include <EEPROM.h>
//indirizzi EEProm
int EEPROMaddr = 10; // 10 = Mode
int RECV_PIN = 10; // UNO input IR pin 11
bool ProtocolOK;
IRrecv irrecv(RECV_PIN);
decode_results results;
int ledPin = 11; // LED connected to digital pin 9
void setup() {
// nothing happens in setup
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
//RIGA INCRIMINATA INIZIO
//irrecv.enableIRIn(); // Start the receiver
//RIGA INCRIMINATA FINE
}
void dump(decode_results *results) {
// Dumps out the decode_results structure.
// Call this after IRrecv::decode()
int count = results->rawlen;
ProtocolOK = false;
if (results->decode_type == UNKNOWN) {
Serial.print("Unknown encoding: ");
}
else if (results->decode_type == NEC) {
Serial.print("Decoded NEC: ");
}
else if (results->decode_type == SONY) {
Serial.print("Decoded SONY: ");
}
else if (results->decode_type == RC5) {
ProtocolOK = true;
Serial.print("Decoded RC5: ");
}
else if (results->decode_type == RC6) {
Serial.print("Decoded RC6: ");
}
else if (results->decode_type == PANASONIC) {
Serial.print("Decoded PANASONIC - Address: ");
Serial.print(results->address, HEX);
Serial.print(" Value: ");
}
else if (results->decode_type == LG) {
Serial.print("Decoded LG: ");
}
else if (results->decode_type == JVC) {
Serial.print("Decoded JVC: ");
}
else if (results->decode_type == AIWA_RC_T501) {
Serial.print("Decoded AIWA RC T501: ");
}
else if (results->decode_type == WHYNTER) {
Serial.print("Decoded Whynter: ");
}
if (ProtocolOK == true)
{
Serial.print(results->value, HEX);
Serial.print(" (");
}
else
{
Serial.println("prot-error");
}
ProtocolOK = false;
results->decode_type = UNKNOWN;
}
void loop() {
if (irrecv.decode(&results)) {
dump(&results);
irrecv.resume(); // Receive the next value
}
// fade in from min to max in increments of 5 points:
for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
Serial.println(fadeValue);
}
// fade out from max to min in increments of 5 points:
for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
Serial.println(fadeValue);
}
}