Jump to content
 

Estreetcar

Members
  • Posts

    31
  • Joined

  • Last visited

Everything posted by Estreetcar

  1. All- Ok, I had some time today. I got the analog inputs working. I could really use help on the "release" function. and the continuous rotation for Route 200. Thanks again for a starting point for the code. Below is the code as well as a download file for those that prefer it that way. I am sure I will try and get it a little cleaner, but it works.... so I am happy. Any suggestions for consolidation would be appreciated. DCC_Turntable_Rev_3.ino -Eric //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // // DCC Turntable Rev_3 Mar_21_2014 // based on code from rmweb.co.uk forum // edited by E.Sitiko // This is a work in progress, I need some help with programming // Changes desired are: // 12 road turntable (works) // DCC addresses 200 to 212 (works) // "Real World" interface // 2- N.O. Push buttons to enable move to "Head" or "Tail" (works) // 1- 10k Continuous turn POT to select track. (works) // 1- N.O. Reset button on fascia (works) // // (future) Address 200= continuous slow rotation, based on "Head" or "Tail" // (future) A "Release" function, universal to operation, that would release power // to the table after sitting idle for 2-3 min. Right now, you just call up // the same function again and it will "release" // //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // // DCC Turntable Control Routines #include <DCC_Decoder.h> #include <AccelStepper.h> #include <Wire.h> #include <Adafruit_MotorShield.h> #include "utility/Adafruit_PWMServoDriver.h" ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Defines and structures // #define kDCC_INTERRUPT 0 typedef struct { int address; // Address to respond to } DCCAccessoryAddress; DCCAccessoryAddress gAddresses[13]; //configure alalog pin 1 as an input int analogPin = 1; // potentiometer wiper (middle terminal) connected to analog pin 1 // outside leads to ground and +5V int potDisp = 0; // variable to store the value read int potOut = 0; int sensorOut = 0; int delayvalue = 500; // makes default delay value boolean AnalogOut = false; int sensorHead = digitalRead(4); int sensorTail = digitalRead(5); //location variables int A = 150; //TT Track 0- Head int B = 45; //TT Track 1- Head int C = 205; //TT Track 2- Head int D = 490; //TT Track 3- Head int E = 588; //TT Track 4- Head int F = 765; //TT Track 5- Head int G = 1939; //TT Track 6- Head int H = 2072; //TT Track 7- Head int I = 2205; //TT Track 8- Head int J= 2499; //TT Track 9- Head int K = 2623; //TT Track 10- Head int L = 2739; //TT Track 11- Head int M = 2872; //TT Track 12- Head int N = 1750; //TT Track 0- Tail int O = 1645; //TT Track 1- Tail int P = 1805; //TT Track 2- Tail int Q = 2090; //TT Track 3- Tail int R = 2188; //TT Track 4- Tail int S = 2365; //TT Track 5- Tail int T = 339; //TT Track 6- Tail int U = 472; //TT Track 7- Tail int V = 605; //TT Track 8- Tail int W = 899; //TT Track 9- Tail int X = 1023; //TT Track 10- Tail int Y = 1139; //TT Track 11- Tail int Z = 1272; //TT Track 12- Tail int TrackPos[13]={A,B,C,D,E,F,G,H,I,J,K,L,M}; int TrackNeg[13]={N,O,P,Q,R,S,T,U,V,W,X,Y,Z}; //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // // Adafruit Setup Adafruit_MotorShield AFMStop(0x60); // Default address, no jumpers // Connect stepper with 200 steps per revolution (1.8 degree) // to the M3, M4 terminals (blue,yellow,green,red) Adafruit_StepperMotor *myStepper2 = AFMStop.getStepper(200, 2); // you can change these to SINGLE, DOUBLE, INTERLEAVE or MICROSTEP! // wrapper for the motor! (3200 Microsteps/revolution) void forwardstep2() { myStepper2->onestep(BACKWARD, MICROSTEP); } void backwardstep2() { myStepper2->onestep(FORWARD, MICROSTEP); } void release2() { myStepper2->release(); } // Now we'll wrap the stepper in an AccelStepper object AccelStepper stepper2(forwardstep2, backwardstep2); ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Decoder Init // void ConfigureDecoder() { gAddresses[0].address = 200; gAddresses[1].address = 201; gAddresses[2].address = 202; gAddresses[3].address = 203; gAddresses[4].address = 204; gAddresses[5].address = 205; gAddresses[6].address = 206; gAddresses[7].address = 207; gAddresses[8].address = 208; gAddresses[9].address = 209; gAddresses[10].address = 210; gAddresses[11].address = 211; gAddresses[12].address = 212; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Basic accessory packet handler // void BasicAccDecoderPacket_Handler(int address, boolean activate, byte data) { int delayvalue = 500; // Convert NMRA packet address format to human address address -= 1; address *= 4; address += 1; address += (data & 0x06) >> 1; boolean enable = (data & 0x01) ? 1 : 0; for(int i=0; i<(int)(sizeof(gAddresses)/sizeof(gAddresses[0])); i++) { if( address == gAddresses[i].address ) { Serial.print("Basic addr: "); Serial.print(address,DEC); Serial.print(" activate: "); Serial.println(enable,DEC); if( enable ) { switch (i) { case 0: stepper2.moveTo(A); delay(delayvalue); //release2(); break; case 1: stepper2.moveTo(B); delay(delayvalue); release2(); break; case 2: stepper2.moveTo(C); delay(delayvalue); release2(); break; case 3: stepper2.moveTo(D); delay(delayvalue); release2(); break; case 4: stepper2.moveTo(E); delay(delayvalue); release2(); break; case 5: stepper2.moveTo(F); delay(delayvalue); release2(); break; case 6: stepper2.moveTo(G); delay(delayvalue); release2(); break; case 7: stepper2.moveTo(H); delay(delayvalue); release2(); break; case 8: stepper2.moveTo(I); delay(delayvalue); release2(); break; case 9: stepper2.moveTo(J); delay(delayvalue); release2(); break; case 10: stepper2.moveTo(K); delay(delayvalue); release2(); break; case 11: stepper2.moveTo(L); delay(delayvalue); release2(); break; case 12: stepper2.moveTo(M); delay(delayvalue); release2(); break; } }else{ switch (i) { case 0: stepper2.moveTo(N); delay(delayvalue); release2(); break; case 1: stepper2.moveTo(O); delay(delayvalue); release2(); break; case 2: stepper2.moveTo(P); delay(delayvalue); release2(); break; case 3: stepper2.moveTo(Q); delay(delayvalue); release2(); break; case 4: stepper2.moveTo(R); delay(delayvalue); release2(); break; case 5: stepper2.moveTo(S); delay(delayvalue); release2(); break; case 6: stepper2.moveTo(T); delay(delayvalue); release2(); break; case 7: stepper2.moveTo(U); delay(delayvalue); release2(); break; case 8: stepper2.moveTo(V); delay(delayvalue); release2(); break; case 9: stepper2.moveTo(W); delay(delayvalue); release2(); break; case 10: stepper2.moveTo(X); delay(delayvalue); release2(); break; case 11: stepper2.moveTo(Y); delay(delayvalue); release2(); break; case 12: stepper2.moveTo(Z); delay(delayvalue); release2(); break; } } } } } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // // Trial Analog In sub-routine // /////////////////////////////////////// void analog() //(int potOut, boolean HeadOut, boolean TailOut) { int sensorHead = digitalRead(4); int sensorTail = digitalRead(5); while (sensorHead == LOW) { sensorHead = digitalRead(4); delay(100); if (sensorHead == 0); {AnalogOut = 1;}} while (sensorTail == LOW) { sensorTail = digitalRead(5); delay(100); if (sensorTail == 0); {AnalogOut = 0;}} //configure alalog pin 1 as an input int potDisp = analogRead(1); int potOut = potDisp / 79; //1023 / 13 Serial.print("Analog Location: "); Serial.println(potOut); Serial.print("Track #: "); Serial.print(potOut,DEC); Serial.print(" activate: "); Serial.println(AnalogOut,DEC); if(AnalogOut == 1) { switch (potOut) { case 0: stepper2.moveTo(A); delay(delayvalue); //release2(); break; case 1: stepper2.moveTo(B); delay(delayvalue); release2(); break; case 2: stepper2.moveTo(C); delay(delayvalue); release2(); break; case 3: stepper2.moveTo(D); delay(delayvalue); release2(); break; case 4: stepper2.moveTo(E); delay(delayvalue); release2(); break; case 5: stepper2.moveTo(F); delay(delayvalue); release2(); break; case 6: stepper2.moveTo(G); delay(delayvalue); release2(); break; case 7: stepper2.moveTo(H); delay(delayvalue); release2(); break; case 8: stepper2.moveTo(I); delay(delayvalue); release2(); break; case 9: stepper2.moveTo(J); delay(delayvalue); release2(); break; case 10: stepper2.moveTo(K); delay(delayvalue); release2(); break; case 11: stepper2.moveTo(L); delay(delayvalue); release2(); break; case 12: stepper2.moveTo(M); delay(delayvalue); release2(); break; } }else { switch (potOut) { case 0: stepper2.moveTo(N); delay(delayvalue); release2(); break; case 1: stepper2.moveTo(O); delay(delayvalue); release2(); break; case 2: stepper2.moveTo(P); delay(delayvalue); release2(); break; case 3: stepper2.moveTo(Q); delay(delayvalue); release2(); break; case 4: stepper2.moveTo(R); delay(delayvalue); release2(); break; case 5: stepper2.moveTo(S); delay(delayvalue); release2(); break; case 6: stepper2.moveTo(T); delay(delayvalue); release2(); break; case 7: stepper2.moveTo(U); delay(delayvalue); release2(); break; case 8: stepper2.moveTo(V); delay(delayvalue); release2(); break; case 9: stepper2.moveTo(W); delay(delayvalue); release2(); break; case 10: stepper2.moveTo(X); delay(delayvalue); release2(); break; case 11: stepper2.moveTo(Y); delay(delayvalue); release2(); break; case 12: stepper2.moveTo(Z); delay(delayvalue); release2(); break; } } } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // // Setup // void setup() { Serial.begin(9600); AFMStop.begin(); // Start the shield //configure pin3 as an input and enable the internal pull-up resistor pinMode(3, INPUT_PULLUP); //configure pin4 as an input and enable the internal pull-up resistor pinMode(4, INPUT_PULLUP); //configure pin5 as an input and enable the internal pull-up resistor pinMode(5, INPUT_PULLUP); //read the sensoron Dig I/O #3 (open collector type) value into a variable int sensorVal = digitalRead(3); //set stepper motor speed and acceleration stepper2.setMaxSpeed(80.0); stepper2.setAcceleration(10.0); // if near reference point move away while (sensorVal == LOW) { sensorVal = digitalRead(3); forwardstep2(); delay(50); Serial.println("Stepper Home"); } // step backrward to sensor index point while (sensorVal == HIGH) { sensorVal = digitalRead(3); backwardstep2(); delay(50); } DCC.SetBasicAccessoryDecoderPacketHandler(BasicAccDecoderPacket_Handler, true); ConfigureDecoder(); DCC.SetupDecoder( 0x00, 0x00, kDCC_INTERRUPT ); } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Main loop // void loop() { static int addr = 0; //////////////////////////////////////////////////////////////// // Loop DCC library DCC.loop(); //////////////////////////////////////////////////////////////// // Bump to next address to test if( ++addr >= (int)(sizeof(gAddresses)/sizeof(gAddresses[0])) ) { addr = 0; } //The analog input section of the loop text //read the sensor (open collector type) value into a variable int sensorHead = digitalRead(4); //read the sensor (open collector type) value into a variable int sensorTail = digitalRead(5); while (sensorHead == LOW) { sensorHead = digitalRead(4); delay(100); Serial.println("Head Pressed"); analog();} while (sensorTail == LOW) { sensorTail = digitalRead(5); delay(100); Serial.println("Tail Pressed"); analog();} // Run the Stepper Motor // stepper2.run(); } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2. Robin- I agree completely. That is what I was thinking. I have resolved the pot reading into 0-12. I just don't know how or where to get that output value into a working function so that it does something. I searched for example code and haven't found anything. Would it be in another expression similar to the DCC code? If so,what would that look like? I don't think I should have the push buttons in the "loop" function, but I found that was where they worked (by trial and error). I would think I should refer to something in the loop and then make a new function to call the pot value, look for push button and then execute the move of the stepper. What would that syntax look like? It isn't code but the logic stream to me would be like this: In the loop: Look at state of the DCC code (as is), add looking at the state of the two push buttons.. If DCC code is within address range => run dcc function If Either push button goes LOW => run Push button function The functions: DCC function- as is, {maybe make position a global variable defined at the beginning so the values can be referenced from either function (DCC or Button)} Push Button function- copy of DCC function with analog value in place of address. Thanks -Eric
  3. No reason really. But I do have 12 tracks (13 if you include the "0" track) and I had a 10k pot on hand. I would need to multi-plex the inputs to fit them all into the arduino... so, I thought just an analog signal would work. I was able to recognize the position of the Pot reliably, I just don't know how to write the code to make it do anything useful. This bit of code recognizes the input and outputs an integer 0~12 based on position of the knob. //configure alalog pin 1 as an input int potDisp = 1; int reading = analogRead(potDisp); int analogout = reading / 79; //1023 / 13 The value is displayed when you make a DCC address selection (as part of that routine). It is not ideal, but I wanted to see if I could read the value before I tried to make it perform work. Serial.print("Analog Location: "); Serial.println(analogout); I am building two of these set-ups. One for home and one for the club. At the club the dial and push button will be easier for members to work with. The club layout has a roundhouse with 13 roads. My plan is to get mine working perfectly at home, then tackle the retrofit of the club layout. I purchased all these parts a few months ago on a whim, then found your post about halfway through the design. I really like the code you have written. It works! I did use a bigger stepper motor because I had it from another project. -Eric
  4. Robin- Thanks for the help. I have fixed the previous posting and also included the arduino *.ino type file as an attachment. -Eric
  5. Robin and All- I think it would be best for me to just paste in the entire code as it is right now. I moved the statements to setup, but I don't understand what you meant by "(And see what putting the code into code tags - the <> icon - does)." I am very new to any type of programming (which should be pretty obvious when you look at my edits!). I really appreciate the help. Thanks -Eric //////////////////////////////////////////////////////////////////////////////// // // DCC Turntable Rev_1 Mar_20_2014 // based on code from rmweb.co.uk forum // edited by E.Sitiko // This is a work in progress, I need some help with programming // Changes desired are: // 12 road turntable (works) // DCC addresses 200 to 212 (works) // "Real World" interface // 2- N.O. Push buttons to enable move to "Head" or "Tail" // 1- 10k Continuous turn POT to select track. // 1- N.O. Reset button on fascia (works) // Address 200= continuous slow rotation, based on "Head" or "Tail" (future) // A "Release" function, universal to operation, that would release power // to the table after sitting idle for 2-3 min. Right now, you just call up // the same function again and it will "release" // //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // // DCC Turntable Control Routines #include <DCC_Decoder.h> #include <AccelStepper.h> #include <Wire.h> #include <Adafruit_MotorShield.h> #include "utility/Adafruit_PWMServoDriver.h" ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Defines and structures // #define kDCC_INTERRUPT 0 typedef struct { int address; // Address to respond to } DCCAccessoryAddress; DCCAccessoryAddress gAddresses[13]; //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // // Adafruit Setup Adafruit_MotorShield AFMStop(0x60); // Default address, no jumpers // Connect stepper with 200 steps per revolution (1.8 degree) // to the M3, M4 terminals (blue,yellow,green,red) Adafruit_StepperMotor *myStepper2 = AFMStop.getStepper(200, 2); // you can change these to SINGLE, DOUBLE, INTERLEAVE or MICROSTEP! // wrapper for the motor! (3200 Microsteps/revolution) void forwardstep2() { myStepper2->onestep(BACKWARD, MICROSTEP); } void backwardstep2() { myStepper2->onestep(FORWARD, MICROSTEP); } void release2() { myStepper2->release(); } // Now we'll wrap the stepper in an AccelStepper object AccelStepper stepper2(forwardstep2, backwardstep2); ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Decoder Init // void ConfigureDecoder() { gAddresses[0].address = 200; gAddresses[1].address = 201; gAddresses[2].address = 202; gAddresses[3].address = 203; gAddresses[4].address = 204; gAddresses[5].address = 205; gAddresses[6].address = 206; gAddresses[7].address = 207; gAddresses[8].address = 208; gAddresses[9].address = 209; gAddresses[10].address = 210; gAddresses[11].address = 211; gAddresses[12].address = 212; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Basic accessory packet handler // void BasicAccDecoderPacket_Handler(int address, boolean activate, byte data) { //configure alalog pin 1 as an input int potDisp = 1; int reading = analogRead(potDisp); int analogout = reading / 79; //1023 / 13 int delayvalue = 500; // Convert NMRA packet address format to human address address -= 1; address *= 4; address += 1; address += (data & 0x06) >> 1; boolean enable = (data & 0x01) ? 1 : 0; for(int i=0; i<(int)(sizeof(gAddresses)/sizeof(gAddresses[0])); i++) { if( address == gAddresses[i].address ) { Serial.print("Analog Location: "); Serial.println(analogout); Serial.print("Basic addr: "); Serial.print(address,DEC); Serial.print(" activate: "); Serial.println(enable,DEC); if( enable ) { switch (i) { case 0: stepper2.moveTo(150); delay(delayvalue); //release2(); break; case 1: stepper2.moveTo(45); delay(delayvalue); release2(); break; case 2: stepper2.moveTo(205); delay(delayvalue); release2(); break; case 3: stepper2.moveTo(490); delay(delayvalue); release2(); break; case 4: stepper2.moveTo(588); delay(delayvalue); release2(); break; case 5: stepper2.moveTo(765); delay(delayvalue); release2(); break; case 6: stepper2.moveTo(1939); delay(delayvalue); release2(); break; case 7: stepper2.moveTo(2072); delay(delayvalue); release2(); break; case 8: stepper2.moveTo(2205); delay(delayvalue); release2(); break; case 9: stepper2.moveTo(2499); delay(delayvalue); release2(); break; case 10: stepper2.moveTo(2623); delay(delayvalue); release2(); break; case 11: stepper2.moveTo(2739); delay(delayvalue); release2(); break; case 12: stepper2.moveTo(2872); delay(delayvalue); release2(); break; } }else{ switch (i) { case 0: stepper2.moveTo(1750); delay(delayvalue); release2(); break; case 1: stepper2.moveTo(1645); delay(delayvalue); release2(); break; case 2: stepper2.moveTo(1805); delay(delayvalue); release2(); break; case 3: stepper2.moveTo(2090); delay(delayvalue); release2(); break; case 4: stepper2.moveTo(2188); delay(delayvalue); release2(); break; case 5: stepper2.moveTo(2365); delay(delayvalue); release2(); break; case 6: stepper2.moveTo(339); delay(delayvalue); release2(); break; case 7: stepper2.moveTo(472); delay(delayvalue); release2(); break; case 8: stepper2.moveTo(605); delay(delayvalue); release2(); break; case 9: stepper2.moveTo(899); delay(delayvalue); release2(); break; case 10: stepper2.moveTo(1023); delay(delayvalue); release2(); break; case 11: stepper2.moveTo(1139); delay(delayvalue); release2(); break; case 12: stepper2.moveTo(1272); delay(delayvalue); release2(); break; } } } } } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Setup // void setup() { Serial.begin(9600); AFMStop.begin(); // Start the shield //configure pin3 as an input and enable the internal pull-up resistor pinMode(3, INPUT_PULLUP); //configure pin4 as an input and enable the internal pull-up resistor pinMode(4, INPUT_PULLUP); //configure pin5 as an input and enable the internal pull-up resistor pinMode(5, INPUT_PULLUP); //read the sensoron Dig I/O #3 (open collector type) value into a variable int sensorVal = digitalRead(3); //set stepper motor speed and acceleration stepper2.setMaxSpeed(80.0); stepper2.setAcceleration(10.0); // if near reference point move away while (sensorVal == LOW) { sensorVal = digitalRead(3); forwardstep2(); delay(50); Serial.println("Stepper Home"); } // step backrward to sensor index point while (sensorVal == HIGH) { sensorVal = digitalRead(3); backwardstep2(); delay(50); } DCC.SetBasicAccessoryDecoderPacketHandler(BasicAccDecoderPacket_Handler, true); ConfigureDecoder(); DCC.SetupDecoder( 0x00, 0x00, kDCC_INTERRUPT ); } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Main loop // void loop() { static int addr = 0; //////////////////////////////////////////////////////////////// // Loop DCC library DCC.loop(); //////////////////////////////////////////////////////////////// // Bump to next address to test if( ++addr >= (int)(sizeof(gAddresses)/sizeof(gAddresses[0])) ) { addr = 0; } stepper2.run(); // This is the questionable area. Trying to make the buttons work. // Currently they just drive the table to a location. I would like them // to direct the type of movement, ie- read analog input (POT) and // take the table to the correct road with either the "Head" or "Tail" end // //read the sensor (open collector type) value into a variable int sensorHead = digitalRead(4); //read the sensor (open collector type) value into a variable int sensorTail = digitalRead(5); // if Head button pushed while (sensorHead == LOW) { sensorHead = digitalRead(4); stepper2.moveTo(45); delay(500); release2(); } // if Tail button pushed while (sensorTail == LOW) { sensorTail = digitalRead(5); stepper2.moveTo(1645); delay(500); release2(); } } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Also- See file in Arduino *.ino format DCC_Turntable_Rev_1.ino ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ That is the end of it. Thanks- Eric DCC_Turntable_Rev_1.ino
  6. Ray- I wanted to say thank you for all the work that went into this. I have built the attached set-up to perform some trials on my own. The turntable it is going on is one that previously had to be lined by eye. This was getting harder as the scene was being built up around it. I have modified your code a little, but I really like the simplicity of the code. And it works! I used a hall sensor that works very reliably. I modified your code so that the table always approaches the sensor from the same side, so that it always reads the same value. I have it mocked up under the layout and tested it for alignment. It works really well. I am very impressed. To work on some "advanced" features I have removed the assemly from the layout and put it on my desk. See attached photo. I made a breakout board with some wafer board, but it follows your design with only the addition of more inputs (see text below): In Set-Up: // if near reference point move away while (sensorVal == LOW) { sensorVal = digitalRead(3); forwardstep2(); delay(50); Serial.println("Stepper Home"); } // step backrward to sensor index point while (sensorVal == HIGH) { sensorVal = digitalRead(3); backwardstep2(); delay(50); As I typically have long ops sessions I wanted a way to kill power to the stepper motor (reduce buzzing, power consumption and heat) when we were finished using the table. I would like to know of a more elegant way to have the "release" command issued 2-3 minutes after the table is in position. case 1: stepper2.moveTo(1902); delay(500); release2(); break; The command "release2()" is defined as : void release2() { myStepper2->release(); This code does work, but not very elegantly. The way it works right now is that you just call up the same item (ie- 201 thrown) again and it will release the motor power after a half second. I would like to make this automatic, but don't know how. The final change is also a big change. I would like to add some analog controls to the fascia of the turntable to allow you to just call up a road with a dial and push button. I have a 10k pot and two normally open push buttons. I have the push buttons wired into Digital I/O 4 & 5, and the pot wired into Analog In 1. I also put a reset button for the fascia panel. I have had success with the push buttons. All three work. The two in the Digial I/O 4 & 5 are currently just set up to move the table to a defined position. It works. The Pot is set up to output a digit 1-12 based on its position. That also works. I don't know how to make the combined solution work with the software. The goal of mine is to line the dial (potentiometer) up with the drawing for the road and then call up a track by pushing either pushbutton. One pushbutton would be “head” end and the other would be the “tail” position. This would relate to the “thrown” and “closed” positions in DCC. To get me closer to the goal, I sketched up some code. This is what I have typed up, but it doesn't work like I want (but it does show the inputs work correctly) in "void loop()" after the text you provided, I wrote: //configure pin4 as an input and enable the internal pull-up resistor pinMode(4, INPUT_PULLUP); //read the sensor (open collector type) value into a variable int sensorHead = digitalRead(4); //configure pin5 as an input and enable the internal pull-up resistor pinMode(5, INPUT_PULLUP); //read the sensor (open collector type) value into a variable int sensorTail = digitalRead(5); // if Head button pushed while (sensorHead == LOW) { sensorHead = digitalRead(4); stepper2.moveTo(150); delay(50); release2(); } // if Tail button pushed while (sensorTail == LOW) { sensorTail = digitalRead(5); stepper2.moveTo(287); delay(50); release2(); } I put the Pot sensor in the "Basic AccessoryPacket Handler" section just so I would be able to see the values easily when I called a DCC track. //configure alalog pin 1 as an input int potDisp = 1; int reading = analogRead(potDisp); int analogout = reading / 79; //1023 / 13 Further down I put the serial print just ahead of the "basic address" serial output line, so that I can see the value Serial.print("Analog Location: "); Serial.println(analogout); That is what I have so far. Any help would be greatly appreciated. I am not sure where to go from here. If anyone wants I can post the complete code in a separate posting for everyone to copy. Thanks -Eric S. Portland, OR USA
×
×
  • Create New...