MOSFET Mayhem..


hey forum,

this post in reference last post mapping analog data shift registers.

to summarize, i'm attempting use n-channel mosfet transistor drive series of leds , brightness (pwm) based on analog data accelerometer. i've succeeded in mapping analog data leds, using pin off arduino each led now, want consolidate , use transistor pwm leds using 1 pin off arduino.

however, i'm stuck - can't turn on leds using transistor. original code used pwm individual pins:

code: [select]
const int xdata = a0;  // analog input pin accelerometer attached to
const int greenpin1 = 2; // analog output pin led attached to
const int greenpin2 = 3;

int sensorvalue = 0;        // value read accelerometer
int outputvalue = 0;        // value output pwm (analog out)

void setup() {
  // initialize serial communications @ 9600 bps:
  serial.begin(9600);
}

void loop() {
  // read analog in value:
  sensorvalue = analogread(xdata);           
  // map range of analog out:
  outputvalue = map(sensorvalue, 0, 525, 0, 654); 
  // change analog out value:
  analogwrite(greenpin1, outputvalue);
  analogwrite(greenpin2, outputvalue);

  // print results serial monitor:
  serial.print("sensor = " );                     
  serial.println(sensorvalue);     
  serial.print("\t output = ");     
  serial.println(outputvalue); 

  // wait 10 milliseconds before next loop
  // analog-to-digital converter settle
  // after last reading:
  delay(50);                   
}


i'm having trouble combining sketch last example sketch proposed nick gammon achieve overall led pwm effect. it's confusing because i'm no longer using shift register sketch implies:

code: [select]
#include <spi.h>

const byte latch = 10;

void setup ()
{
  spi.begin ();
}  // end of setup

const byte maxdimiterations = 63;

byte c;
void loop ()
{
  c++;
 
  (byte bright = 0; bright < maxdimiterations; bright++)
    {
    analogwrite (5, bright * 4);
    digitalwrite (latch, low);
    spi.transfer (c);
    digitalwrite (latch, high);
    delay (10);
    }  // end of for
   
}  // end of loop


not mention example sketch on bildr.org transistors doesn't clarify things..:

code: [select]
//////////////////////////////////////////////////////////////////
//©2011 bildr
//released under mit license - please reuse change , share
//simple code output pwm sine wave signal on pin 9
//////////////////////////////////////////////////////////////////

#define fadepin 3

void setup(){
  pinmode(fadepin, output);
}

void loop(){

  for(int = 0; i<360; i++){
    //convert 0-360 angle radian (needed sin function)
    float rad = deg_to_rad * i;

    //calculate sin of angle number between 0 , 255
    int sinout = constrain((sin(rad) * 128) + 128, 0, 255);

    analogwrite(fadepin, sinout);

    delay(15);
  }

}


any insight can give appreciated. thanks!

that last sketch should work, how have wired , sort of fet using?
a schematic thing post.


Arduino Forum > Using Arduino > LEDs and Multiplexing > MOSFET Mayhem..


arduino

Comments

Popular posts from this blog

Thread: PKI Client 5.00 install (for eToken Pro)

ATmega2560-Arduino Pin Mapping

Crossfader Arduino Tutorial