Lamont's PWM code

From Noisebridge
Revision as of 02:13, 25 March 2009 by Rachel (talk | contribs) (New page: <pre> →‎* 2009-03-24, pager motor test, lamont lucas *: // define the pins used to run the shift registers int enable_low = 5; //enable outputs, low = on int serial_in = 6; int ...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
/*
 * 2009-03-24, pager motor test, lamont lucas
 *
 */

// define the pins used to run the shift registers 
int enable_low = 5;  //enable outputs, low = on
int serial_in  = 6; 
int ser_clear_low = 7;  //pulse low to zero out the shift buffer
int RCK  = 9;  //RCK, push the serial buffer to the outputs
int SRCK = 10;  //

// analog definitions.
// int potPin = 23;    // select the input pin for the potentiometer

void setup() {
  pinMode(enable_low, OUTPUT);  // set shift register pins as outputs
  pinMode(serial_in, OUTPUT);
  pinMode(ser_clear_low, OUTPUT);
  pinMode(RCK, OUTPUT);
  pinMode(SRCK, OUTPUT);
  
  //more test
  //pinMode(11, OUTPUT);
  
  // use some serial for debugging
  Serial.begin(9600);
  Serial.println("Setting up board");
  
  // make sure we start out all off
  digitalWrite(enable_low, HIGH);
  // this should wipe out the serial buffer on the shift register
  digitalWrite(ser_clear_low, LOW);
  delay(100);   //delay in ms
  
  // the TPIC6b595 clocks work on a rising edge, so make sure they're low to start.
  digitalWrite(RCK, LOW);
  digitalWrite(SRCK, LOW);
  
  digitalWrite(ser_clear_low, HIGH);   //we are now clear to write into the serial buffer

  Serial.println("Board is setup");
}


void loop() {
  
  //test statement
  analogWrite(17, 200);
  //raise enable high to disable outputs
  digitalWrite(enable_low, HIGH);
  
  delayMicroseconds(100);  //slow and steady
  //shiftOut(serial_in, SRCK, LSBFIRST, B01010101);
  shiftOut(serial_in, SRCK, LSBFIRST, B11111111);
  //pulse RCK to pop that into the outputs
  delayMicroseconds(100);
  digitalWrite(RCK, HIGH);
  delayMicroseconds(100);
  digitalWrite(RCK, LOW);
  
  for (int i=150; i <= 250; i += 10) {
    Serial.print("Using PWM value of ");
    Serial.println(i);
    //pwm the enable (255 = 0v, 0 = 5v)
    analogWrite(enable_low, i);
    delay(250);
  }
}