Editing
Hack Notes CVA 090617
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Code== <pre> // define the pins used to run the shift registers int enable_low = 6; //STR int serial_in = 2; int ser_clear_low = 4; int RCK = 5; int SRCK = 7; //define transistor pins int T1 = 13; int T2 = 9; int count; int i; unsigned long serialTimer = millis(); 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); // use some serial for debugging Serial.begin(115200); 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 // 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() { Debug(); //promising, but doesn't quite work! /* for(i=0;i<10000;i++){ analogWrite(T2, 0); analogWrite(T1, 255); shiftOut(serial_in, SRCK, LSBFIRST, 00100000); delayMicroseconds(100); digitalWrite(RCK, HIGH); delayMicroseconds(100); digitalWrite(RCK, LOW); analogWrite(T1, 0); analogWrite(T2, 255); shiftOut(serial_in, SRCK, LSBFIRST, 10000000); delayMicroseconds(100); digitalWrite(RCK, HIGH); delayMicroseconds(100); digitalWrite(RCK, LOW); }*/ } //// FUNCTIONS void Debug(){ for(count=1;count<9;count++){ TurnOnMotor(count); delay(500); } } void TurnOnMotor(int which){ // accept which from 1 to 8 // send message to shift register as appropiate digitalWrite(enable_low, HIGH); delayMicroseconds(100); //slow and steady Serial.print("Motor "); Serial.println(which); // print angle switch(which){ case 1: analogWrite(T2, 0); analogWrite(T1, 255); shiftOut(serial_in, SRCK, LSBFIRST, 00010000); break; case 2: analogWrite(T2, 0); analogWrite(T1, 255); shiftOut(serial_in, SRCK, LSBFIRST, 00100000); break; case 3: analogWrite(T2, 0); analogWrite(T1, 255); shiftOut(serial_in, SRCK, LSBFIRST, 01000000); break; analogWrite(T2, 0); analogWrite(T1, 255); case 4: shiftOut(serial_in, SRCK, LSBFIRST, 10000000); break; case 5: analogWrite(T1, 0); analogWrite(T2, 255); shiftOut(serial_in, SRCK, LSBFIRST, 00010000); break; case 6: analogWrite(T1, 0); analogWrite(T2, 255); shiftOut(serial_in, SRCK, LSBFIRST, 00100000); break; case 7: analogWrite(T1, 0); analogWrite(T2, 255); shiftOut(serial_in, SRCK, LSBFIRST, 01000000); break; case 8: analogWrite(T1, 0); analogWrite(T2, 255); shiftOut(serial_in, SRCK, LSBFIRST, 10000000); break; case 0: shiftOut(serial_in, SRCK, LSBFIRST, 0); break; default: // turn them all off shiftOut(serial_in, SRCK, LSBFIRST, 0); } //in all cases, pulse RCK to pop that into the outputs delayMicroseconds(100); digitalWrite(RCK, HIGH); delayMicroseconds(100); digitalWrite(RCK, LOW); analogWrite(enable_low, 0); } </pre>
Summary:
Please note that all contributions to Noisebridge are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
Noisebridge:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
To protect the wiki against automated edit spam, we kindly ask you to solve the following CAPTCHA:
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Log in
Request account
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Dig in!
Noisebridge
- Status: MOVED
- Donate
- ABOUT
- Accessibility
- Vision
- Blog
Manual
MANUAL
Visitors
Participation
Community Standards
Channels
Operations
Events
EVENTS
Guilds
GUILDS
- Meta
- Electronics
- Fabrication
- Games
- Music
- Library
- Neuro
- Philosophy
- Funding
- Art
- Crypto
- Documentation/Wiki
Wiki
Recent Changes
Random Page
Help
Categories
(Edit)
Tools
What links here
Related changes
Special pages
Page information