It looks like you are trying to add another LED/Mosfet? I have done it this way, I have 3 on mine:
To do this I may or may not have used some examples I found on this forum. I basically add the pins I am using (PWM capable) into an array. I have 4 pins defined (3 is in there twice) to get around the array references starting from 0. Probably a better way to do that but this was my quick way round it.
I have basically adapted the code from the example LED Dimmer sketch to work with the array / multiple child devices.
Hopefully thats helpful and what you were after?
// Enable debug prints to serial monitor
#define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
#include <SPI.h>
#include <MySensors.h>
#define SN "MultiDimmableLED"
#define SV "1.1"
#define noLEDs 3
const int LED_Pin[] = {3, 3, 5, 6}; //put 3 in twice as a start from 0 workaround
#define FADE_DELAY 10 // Delay in ms for each percentage fade up/down (10ms = 1s full-range dim)
static int currentLevel = 0; // Current dim level...
MyMessage dimmerMsg(noLEDs, V_DIMMER);
MyMessage lightMsg(noLEDs, V_LIGHT);
/***
* Dimmable LED initialization method
*/
void setup()
{
// not sure this works
// Pull the gateway's current dim level - restore light level upon sendor node power-up
for (int sensor=1; sensor<=noLEDs; sensor++){
request( sensor, V_DIMMER );
}
}
void presentation() {
// Register the LED Dimmable Light with the gateway
for (int sensor=1; sensor<=noLEDs; sensor++){
present(sensor, S_DIMMER);
delay(2);
}
sendSketchInfo(SN, SV);
}
/***
* Dimmable LED main processing loop
*/
void loop()
{
}
void receive(const MyMessage &message) {
if (message.type == V_LIGHT || message.type == V_DIMMER) {
// Retrieve the power or dim level from the incoming request message
int requestedLevel = atoi( message.data );
// Adjust incoming level if this is a V_LIGHT variable update [0 == off, 1 == on]
requestedLevel *= ( message.type == V_LIGHT ? 100 : 1 );
// Clip incoming level to valid range of 0 to 100
requestedLevel = requestedLevel > 100 ? 100 : requestedLevel;
requestedLevel = requestedLevel < 0 ? 0 : requestedLevel;
Serial.print( "Changing LED " );
Serial.print(message.sensor);
Serial.print(", PIN " );
Serial.print( LED_Pin[message.sensor] );
Serial.print(" level to " );
Serial.print( requestedLevel );
Serial.print( ", from " );
Serial.println( currentLevel );
fadeToLevel( requestedLevel, message.sensor );
// Inform the gateway of the current DimmableLED's SwitchPower1 and LoadLevelStatus value...
send(lightMsg.set(currentLevel > 0 ? 1 : 0));
// hek comment: Is this really nessesary?
send( dimmerMsg.set(currentLevel) );
}
}
/***
* This method provides a graceful fade up/down effect
*/
void fadeToLevel( int toLevel, int ledid ) {
int delta = ( toLevel - currentLevel ) < 0 ? -1 : 1;
while ( currentLevel != toLevel ) {
currentLevel += delta;
analogWrite( LED_Pin[ledid], (int)(currentLevel / 100. * 255) );
delay( FADE_DELAY );
}
}