Lamont's PWM code: Difference between revisions
Jump to navigation
Jump to search
(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 ...) |
Elgreengeeto (talk | contribs) No edit summary |
||
Line 71: | Line 71: | ||
</pre> | </pre> | ||
[[Category:Sensebridge]] |
Latest revision as of 11:02, 10 April 2009
/* * 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); } }