This topic contains 2 replies, has 2 voices, and was last updated by  Joao Catarino 1 year, 5 months ago.

  • Author
    Posts
  • #6918
     Joao Catarino 
    Participant

    Hi there guys, I’m initiating on this wonderful world of making, and I already have a 3D printer built be me, a small CNC router, amongst some other machines.
    Recently I decided to print, wire and build a stargate controlled by an Arduino from a Thingiverse’s project but my lack of knowledge on Arduino programming is keeping me from changing the code to do what I want it to do.

    The porject is somewhat amazing, for what it represents, but I wanted to put a push button so that it starts only when pushed. That is where I got stucked, for I don’t know where or how to insert the line or lines of code to make that change.

    Here is the link to Thingiverse project page and the Arduino code that needs to be changed.
    As I’m a beginner I would like you Guys to comment any suggestions or changes to the code, so that I can understand and learn a bit more.

    PS- there’s a new and improved version by the original thing creator, but that’s for another time…

    http://www.thingiverse.com/thing:571853

    
    /* 
    Dialing Sequence program for 3D printed working Stargate
    Written by Cara McNab ( Carasibana )
    This sketch requires the following Libraries:
    Neopixel Library,  available via https://learn.adafruit.com/adafruit-neopixel-uberguide/arduino-library
    Adafruit Motor Shield Library, avaliable via https://learn.adafruit.com/adafruit-motor-shield-v2-for-arduino/install-software
    */
    // Include the Motor shield and NeoPixel Libraries
    #include <Wire.h>
    #include <Adafruit_MotorShield.h>
    #include "Adafruit_PWMServoDriver.h"
    #include <Adafruit_NeoPixel.h>
    
    // Which pin on the Arduino is connected to the NeoPixels
    #define PIN 6
    
    // How many NeoPixels are attached to the Arduino
    #define NUMPIXELS 9
    
    // How many steps are required to advance the Symbol Ring by one symbol *needs tweaking
    int STEPPERSYM = 62;
    
    // Define the Pixel strand item "pixels"
    Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_RGB + NEO_KHZ800);
    
    // Define the colours to use for the NeoPixels
    uint32_t orange = pixels.Color(255,40,5);
    uint32_t off = pixels.Color(0,0,0);
    
    // Create the motor shield object with the default I2C address
    Adafruit_MotorShield AFMS = Adafruit_MotorShield(); 
    
    // Connect a stepper motor with 200 steps per revolution (1.8 degree)
    // to motor port #2 (M3 and M4)
    Adafruit_StepperMotor *myMotor = AFMS.getStepper(400, 2);
    
    // Define Stargate address to be dialed as array
    // These numbers are the references to the Gate symbols, including the point of origin (1)
    // reference can be found here http://rdanderson.com/stargate/glyphs/glyphs.htm 
    
    int SGAddress[] = {27,7,15,32,12,30,1};
    
    // Define delay for Blinking
    int BlinkDelay = 1500; 
    
    void setup() {
      AFMS.begin();  // create with the default frequency 1.6KHz
       
      myMotor->setSpeed(50);  // Set RPM of stepper motor 
      
      pixels.begin(); // This initializes the NeoPixel library.
    }
    
    void loop() {
      
      // make sure all neopixels are off
      for(int i=0;i<NUMPIXELS;i++){
        pixels.setPixelColor(i, off);
      }
      pixels.show(); // This sends the updated pixel color to the hardware.
    
      // Chevron One (( Assumes starting on Earth (1) ))
      int Chevron = 1;
      
      int numStep = (SGAddress[(Chevron-1)] - 1) * STEPPERSYM;
      myMotor->step(numStep, FORWARD, SINGLE);
      pixels.setPixelColor(4, orange);
      pixels.show();
      delay(BlinkDelay);
      pixels.setPixelColor(4, off);
      pixels.setPixelColor(5, orange);
      pixels.show();
      
      // Chevron Two
      
      Chevron = 2 ;
      
      if (SGAddress[(Chevron-1)] > SGAddress[(Chevron-2)]){
       int numStep = ((SGAddress[(Chevron-2)] - 1) + (40 - SGAddress[(Chevron-1)])) * STEPPERSYM;
      }
      else{
        int numStep = (SGAddress[(Chevron-1)] - SGAddress[(Chevron-2)]) * STEPPERSYM;
      }
      myMotor->step(numStep, BACKWARD, SINGLE);
      pixels.setPixelColor(4, orange);
      pixels.show();
      delay(BlinkDelay);
      pixels.setPixelColor(4, off);
      pixels.setPixelColor(6, orange);
      pixels.show();
      
      // Chevron Three * Needs Tweaking
      
      Chevron = 3 ;
      
      if (SGAddress[(Chevron-1)] > SGAddress[(Chevron-2)]){
       int numStep = ((SGAddress[(Chevron-2)] - 1) + (40 - SGAddress[(Chevron-1)])) * STEPPERSYM;
      }
      else{
        int numStep = (SGAddress[(Chevron-1)] - SGAddress[(Chevron-2)]) * STEPPERSYM;
      }
      myMotor->step(numStep, FORWARD, SINGLE);
      pixels.setPixelColor(4, orange);
      pixels.show();
      delay(BlinkDelay);
      pixels.setPixelColor(4, off);
      pixels.setPixelColor(7, orange);
      pixels.show();
      
      // Chevron Four
      
      Chevron = 4 ;
      
      if (SGAddress[(Chevron-1)] > SGAddress[(Chevron-2)]){
       int numStep = ((SGAddress[(Chevron-2)] - 1) + (40 - SGAddress[(Chevron-1)])) * STEPPERSYM;
      }
      else{
        int numStep = (SGAddress[(Chevron-1)] - SGAddress[(Chevron-2)]) * STEPPERSYM;
      }
      myMotor->step(numStep, BACKWARD, SINGLE);
      pixels.setPixelColor(4, orange);
      pixels.show();
      delay(BlinkDelay);
      pixels.setPixelColor(4, off);
      pixels.setPixelColor(1, orange);
      pixels.show();
      
      // Chevron Five * Needs Tweaking
      
      Chevron = 5 ;
      
      if (SGAddress[(Chevron-1)] > SGAddress[(Chevron-2)]){
       int numStep = ((SGAddress[(Chevron-2)] - 1) + (40 - SGAddress[(Chevron-1)])) * STEPPERSYM;
      }
      else{
        int numStep = (SGAddress[(Chevron-1)] - SGAddress[(Chevron-2)]) * STEPPERSYM;
      }
      myMotor->step(numStep, FORWARD, SINGLE);
      pixels.setPixelColor(4, orange);
      pixels.show();
      delay(BlinkDelay);
      pixels.setPixelColor(4, off);
      pixels.setPixelColor(2, orange);
      pixels.show();
      
      // Chevron Six
      
      Chevron = 6 ;
      
      if (SGAddress[(Chevron-1)] > SGAddress[(Chevron-2)]){
       int numStep = ((SGAddress[(Chevron-2)] - 1) + (40 - SGAddress[(Chevron-1)])) * STEPPERSYM;
      }
      else{
        int numStep = (SGAddress[(Chevron-1)] - SGAddress[(Chevron-2)]) * STEPPERSYM;
      }
      myMotor->step(numStep, BACKWARD, SINGLE);
      pixels.setPixelColor(4, orange);
      pixels.show();
      delay(BlinkDelay);
      pixels.setPixelColor(4, off);
      pixels.setPixelColor(3, orange);
      pixels.show();
      
     // Chevron Seven * Needs Tweaking
      
      Chevron = 7 ;
      
      if (SGAddress[(Chevron-1)] > SGAddress[(Chevron-2)]){
       int numStep = ((SGAddress[(Chevron-2)] - 1) + (40 - SGAddress[(Chevron-1)])) * STEPPERSYM;
      }
      else{
        int numStep = (SGAddress[(Chevron-1)] - SGAddress[(Chevron-2)]) * STEPPERSYM;
      }
      myMotor->step(numStep, FORWARD, SINGLE);
      pixels.setPixelColor(4, orange);
      pixels.show();
      delay(BlinkDelay);
      pixels.setPixelColor(0, orange);
      pixels.setPixelColor(8, orange);
      pixels.show();
      
      // Restart Sequence     (I think is from/here where I have to insert the new lines of code)
      delay(1000000);
    
    }
    • This topic was modified 1 year, 5 months ago by  Luís Carvão.
    #6936
     Luís Carvão 
    Keymaster

    Hi there João,

    first of all thank you for posting your project and being the first!

    As for your project to work with a button you need to define this new input on the code, define its pin number and then add to the first lines of “void loop” a code to give priority to the button. The leds and the motor will only start if the button is pressed.

    
    const int buttonPin = 2;     // pushbutton pin number
    
    int buttonState = 0;         // variable for reading the pushbutton status
    
    void setup() {
      pinMode(buttonPin, INPUT); // initialize the pushbutton pin as an input
    }
    
    void loop() {
      buttonState = digitalRead(buttonPin); // read the state of the pushbutton value
     // check if the pushbutton is pressed.
      // if it is, the buttonState is HIGH:
      if (buttonState == HIGH) {  
    // make sure all neopixels are off
      for(int i=0;i<NUMPIXELS;i++){
        pixels.setPixelColor(i, off);
      }
      // Chevron One (( Assumes starting on Earth (1) ))
      int Chevron = 1;
      
      int numStep = (SGAddress[(Chevron-1)] - 1) * STEPPERSYM;
      myMotor->step(numStep, FORWARD, SINGLE);
      pixels.setPixelColor(4, orange);
      pixels.show();
      delay(BlinkDelay);
      pixels.setPixelColor(4, off);
      pixels.setPixelColor(5, orange);
      pixels.show();
      
      // Chevron Two
      
      Chevron = 2 ;
      //........and so on.......
      }
    
    else {
        // make sure all neopixels are off
      for(int i=0;i<NUMPIXELS;i++){
        pixels.setPixelColor(i, off);
      }
      pixels.show(); // This sends the updated pixel color to the hardware.
    }
    

    The full code is not here. Just remember to put these lines on the right place.

    Let me know if it worked!

    #6944
     Joao Catarino 
    Participant

    Hi there Luis, I’ve got this error and I don’t see were to correct it .


    DialingSequence.ino: In function ‘void setup()’:
    DialingSequence:62: error: a function-definition is not allowed here before ‘{‘ token
    void loop() {
    a function-definition is not allowed here before ‘{‘ token “

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

CONTACT US

We're not around right now. But you can send us an email and we'll get back to you, asap.

©2017 KLEO Template a premium and multipurpose theme from Seventh Queen

or

Log in with your credentials

or    

Forgot your details?

or

Create Account