Welcome, %1$s. Please login or register. - Did you miss your activation email?

Login with username, password and session length
 

Author Topic: Less than Noob Needs help  (Read 356 times)

Offline NMSquirrel

  • knowledge leech
  • Commander
  • ***
  • Posts: 233
  • you dont wanna know where this squirrel has gone.
    • Squirrels Nest
Less than Noob Needs help
« on: June 26, 2018, 01:04:03 pm »
I just can't seem to get a handle on the programming part..
what i am after seems simple enough..

8 Leds surrounding a Center Led..
the 8 lighting up in sequence till all are on, then the center LED doing a star trek-esque photon sequence, (like this one: https://www.youtube.com/watch?v=8eyUQsfF2CM ) then all turning off and reseting

I managed to get the Shift Register Lesson loaded and running with the 8 LEDs, but can't figure out how to add in a photon effect..it's the code that is confusing me, i tried to add in the Fading lesson into the shift register lesson, but fail every time i try..i have no clue what i am doing..

i have seen Gadgetrons photon but don't need two photons and have no clue how to reduce the code for my needs..
(or add it to the shift register code)

I can Emblazon yur name on my Death Star (in binary) forever as thanks..If someone can help me get this running..



Offline MarkW

  • Plastic Surgeon
  • Admiral
  • *****
  • Posts: 1347
    • MW ModelWerks
Re: Less than Noob Needs help
« Reply #1 on: June 26, 2018, 05:58:50 pm »
Ok, so first things first.  Start with mapping out what you want the code to do. 

1.  Turn on 8 perimeter LEDs and keep them on in Abbott a second or so.  To me, that seemed like a simple millis.counting loop.  Turn them on, leave them on. 

2.  Photon flash with a green/white LED.  Photon flash for star trek models use a red/white LED, I am assuming there is a similar thing for green LEDs.  This should also be another millis type loop.

3.  After you have obliterated Alderaan or Scarif, one third loop to turn everything off.  This should be a simple counter loop.  Basically for i=0-8 (zero being the first LED, eight being the ninth LED), turn off the LEDs.  this loophole executes so fast that it will appear instantaneous.

 You should be able to do the first and third loop by yourself.   Turn them all on in sequence, and essentially turn them all off at the same time. Once you figure out how you want to physically do the photon flash, whether it is a dual color green/white LED, or you just want to use a larger green LED and have it flashed to a higher brightness, I can help you with that middle loop.

MarkW
"I can cross stab Hitler to death off the list of cool crap I thought I'd never do"
--Brock Sampson
NEW WEB ADDRESS

Offline NMSquirrel

  • knowledge leech
  • Commander
  • ***
  • Posts: 233
  • you dont wanna know where this squirrel has gone.
    • Squirrels Nest
Re: Less than Noob Needs help
« Reply #2 on: June 26, 2018, 07:13:22 pm »
"You should be able to do the first and third loop by yourself."
most of what you said is greek to me..

but yes, the 8 LED i had up and running with the shift register lesson from the arduino docs..
yes green LEDS..

the 8 is a power build up(each led lights after the last)  that sets off the center sequence, the photon flash..
here is what i am working with:
(8 around center, then three tied together for center, i have room for a white in the very center..)
(using prewired 402 SMD's)



« Last Edit: June 26, 2018, 07:24:00 pm by NMSquirrel »

Offline NMSquirrel

  • knowledge leech
  • Commander
  • ***
  • Posts: 233
  • you dont wanna know where this squirrel has gone.
    • Squirrels Nest
Re: Less than Noob Needs help
« Reply #3 on: June 26, 2018, 07:25:55 pm »
and just for bragging..
it is an old (cardboard) globe turned death star,
the dish is made from recycled plastic and a washer for the center..
already drilled 6 sections of about 80, with .5mm (started with .7, then reduced) to be threaded with fiber optic..

« Last Edit: June 26, 2018, 07:27:51 pm by NMSquirrel »

Offline MarkW

  • Plastic Surgeon
  • Admiral
  • *****
  • Posts: 1347
    • MW ModelWerks
Re: Less than Noob Needs help
« Reply #4 on: June 26, 2018, 07:56:51 pm »
Are you going Rogue One, or New hope? :)

I'll try to post some code tomorrow to help out.  I'm not familiar with the shift registers method, but will get you some other ideas.
MarkW
"I can cross stab Hitler to death off the list of cool crap I thought I'd never do"
--Brock Sampson
NEW WEB ADDRESS

Offline NMSquirrel

  • knowledge leech
  • Commander
  • ***
  • Posts: 233
  • you dont wanna know where this squirrel has gone.
    • Squirrels Nest
Re: Less than Noob Needs help
« Reply #5 on: June 26, 2018, 08:45:05 pm »
8 LED's and a shift register is lesson 14 in the arduino tutorials..
it uses less pin-outs
it lights up one LED after the other..


/*
 * Author: SMRAZA KEEN
 * Date:2016/6/29
 * IDE V1.6.9
 * Email:TechnicSmraza@outlook.com
 * Function:
 */
int latchPin = 5;
int clockPin = 6;
int dataPin = 4;
byte leds = 0;
 
void setup()
{
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT); 
  pinMode(clockPin, OUTPUT);
}
void loop()
{
  leds = 0;
  updateShiftRegister();
  delay(500);
  for (int i = 0; i < 8; i++)
  {
    bitSet(leds, i);
    updateShiftRegister();
    delay(500);
  }
}
 
void updateShiftRegister()
{
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, LSBFIRST, leds);
   digitalWrite(latchPin, HIGH);
}


(https://mega.nz/#F!F1gj0Y7L!vrf91AD2b5OowYc43dSR7Q)

« Last Edit: June 26, 2018, 08:48:08 pm by NMSquirrel »

Offline NMSquirrel

  • knowledge leech
  • Commander
  • ***
  • Posts: 233
  • you dont wanna know where this squirrel has gone.
    • Squirrels Nest
Re: Less than Noob Needs help
« Reply #6 on: June 27, 2018, 10:08:16 am »

Offline MarkW

  • Plastic Surgeon
  • Admiral
  • *****
  • Posts: 1347
    • MW ModelWerks
Re: Less than Noob Needs help
« Reply #7 on: June 30, 2018, 09:47:59 am »
Here is a very different approach I took that doesn't involve any additional libraries.  The flash is predicated upon pressing a physical button, which sets a flag in the code. That is why I made that original reference at the top of the post regarding a button press that ignites the torpedo flash, and then a flag at the end of the flash code that stops it from endlessly repeating.

MarkW
"I can cross stab Hitler to death off the list of cool crap I thought I'd never do"
--Brock Sampson
NEW WEB ADDRESS

Offline MarkW

  • Plastic Surgeon
  • Admiral
  • *****
  • Posts: 1347
    • MW ModelWerks
MarkW
"I can cross stab Hitler to death off the list of cool crap I thought I'd never do"
--Brock Sampson
NEW WEB ADDRESS

Offline NMSquirrel

  • knowledge leech
  • Commander
  • ***
  • Posts: 233
  • you dont wanna know where this squirrel has gone.
    • Squirrels Nest
Re: Less than Noob Needs help
« Reply #9 on: June 30, 2018, 02:17:52 pm »
Wow..there is a LOT on information in that thread..
I linked it to a guy who is helping me on facebook, maybe he can make more sense of that..
Oh as far as endlessly repeating, he said it would be possible to cycle it once an hour..

Here is what he came up with so far:
(everything good except no photon/ramp effect)
(Video of my build from his Help (without buttons, I added the buttons later): https://www.facebook.com/NMSquirrel/videos/2008673155811396/?lst=100000061929703%3A100000061929703%3A1530385858  )


/#include "Arduino.h"

//   Name: Death Star Super Laser Example
//   Author Travis Durf
//   Created 6/20/18
//   Version 1.0

//   Circuit setup.  It is using two buttons on Pin2 and Pin4 (with 10k resistors to help with debounce wired from the Pin side to Ground.)
//      There is a 74HC595 connected to Pins 8, 11 and 12, which intern is wired to 8 LEDS (with 470 Ohm resistors to each LED).  These are the ring lights.
//      There is another LED on Pin 6 with a 470 Ohm resistor as well. This is the "center" of the Super Laser.
//      As an additional functional example the second button toggles the flashing of the built in LED on Pin 13.

//    Based on Shift Register, Switch, Blink Without Delay Examples as well as
//      from this thread (http://scifimodelaction.com/sfmaforum/index.php?topic=4793.msg64349#msg64349)
//    Some part was Based on original Arduino sketch by Jack Christensen
//    (http://forum.arduino.cc/index.php?topic=220026.msg1607277#msg1607277).

const int buttonPin = 2;     // the number of the pushbutton pin
const int buttonPin2 = 4;     // the number of the pushbutton pin

//LED pin numbers
const byte LED1 = 6;
const byte LED2 = 13;

bool cylState = false; //Start the LED1 Flash Cycle

//Pin connected to ST_CP (RCLK) 12 of 74HC595
int latchPin = 8;
//Pin connected to SH_CP (SRCLK) 11 of 74HC595
int clockPin = 12;
////Pin connected to DS (SER) 14 of 74HC595
int dataPin = 11;

//holders for information you're going to pass to shifting function
byte data;
byte dataArray[11];


int buttonState = 0;         // variable for reading the buttonPin pushbutton status
int lastButtonState = LOW;   // the previous reading from the input buttonPin pin

int buttonState2 = 0;         // variable for reading the buttonPin2 pushbutton status
int lastButtonState2 = LOW;   // the previous reading from the input buttonPin pin


// the follow variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
// "unsigned" is because they are comparing to "millis()" later on
unsigned long time = 0;         // the last time the output pin was toggled buttonPin
unsigned long time2 = 0;         // the last time the output pin was toggled buttonPin2
unsigned long debounce = 300;   // the debounce time, increase if the output flickers


void setup(void)
{
   // initialize the pushbutton pins as an inputs:
   pinMode(buttonPin, INPUT);
   pinMode(buttonPin2, INPUT);

    pinMode(LED1, OUTPUT); //make each LED pin an output
    pinMode(LED2, OUTPUT); //make each LED pin an output

    pinMode(latchPin, OUTPUT); //initialize the pins for the Shift Register
    pinMode(clockPin, OUTPUT);
    pinMode(dataPin, OUTPUT);

    Serial.begin(9600);//This is so we can send data to the Serial Monitor for debugging feedback for Serial.println.

    //Binary notation as comment These entries are our Shift Register light up patterns
    dataArray[0] = 0b00000000;// For the "binary" entry is enable/disable output 1-8 on the Shift Register
    dataArray[1] = 0b01001000;// this makes this type of entry good for making a visual pattern.
    dataArray[2] = 0b01001010;
    dataArray[3] = 0b11001010;
    dataArray[4] = 0b11101010;
    dataArray[5] = 0b11101110;
    dataArray[6] = 0b11111110;
    dataArray[7] = 0b11111111;
    dataArray[8] = 0b11111111;
    dataArray[9] = 0b11111111;
    dataArray[10] = 0b00000000;

   digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, dataArray[0]); // Clear the Shift Register Display using the 0b00000000 entry, otherwise it remembers the last entry.
   digitalWrite(latchPin, HIGH);
}

void loop(void)
{

   runToggleBtn();  //checks and saves a toggled state for buttonState2
   runPressBtn(); //checks and saves a toggled state for buttonState

   runShift1f(); //calls the Shift Register code
   runLED1f1(); //calls up the Pulse LED


//   if (buttonState== HIGH){
//      Serial.println("button state: " + String(buttonState));
//   }


   if (buttonState2== HIGH){
   runLED2();// Blinks LED2
   //      Serial.println("button state2: " + String(buttonState2));
   }
   else
   {
      digitalWrite(LED2, LOW);// Turns off LED2 incase it was on when the button was toggled

   }

}


// This button "toggles" "buttonState2 for the "runLED2" process blinking the LED2 pin.
void runToggleBtn(void)
{
   int reading;           // the current reading from the input pin

     // read the state of the switch into a local variable:
     reading = digitalRead(buttonPin2);

     // if the input just went from LOW and HIGH and we've waited long enough
       // to ignore any noise on the circuit, toggle the output pin and remember
       // the time
       if (reading == HIGH && lastButtonState2 == LOW && millis() - time2 > debounce) {
         if (buttonState2 == HIGH)
            buttonState2 = LOW;
         else
            buttonState2 = HIGH;

         time2 = millis();
       }
}

// This button sets "buttonstate" which is used to tell "runShift1f" to run the Shift Register outputs
void runPressBtn(void)
{
   unsigned int reading; // the current reading from the input pin

     // read the state of the switch into a local variable:
     reading = digitalRead(buttonPin);

     // if the input just went from LOW and HIGH and we've waited long enough
       // to ignore any noise on the circuit, toggle the output pin and remember
       // the time
       if (reading == HIGH && lastButtonState == LOW && millis() - time > debounce) {
         if (buttonState == HIGH)
            buttonState = LOW;
         else
            buttonState = HIGH;

         time = millis();
       }
}

void runShift1f(void)
{
   // Generally, you should use "unsigned long" for variables that hold time
   // The value will quickly become too large for an int to store
   static unsigned long previousMillis01 = 0; // will store last time LED was updated

   unsigned long currentMillis = millis();
   const long pinterval = 400; // interval at which to blink (milliseconds)
   static unsigned int ppos01 = 0;

   if (buttonState==HIGH) {

   }

     if (currentMillis - previousMillis01 >= pinterval && buttonState==HIGH) {

        digitalWrite(latchPin, LOW);

        shiftOut(dataPin, clockPin, MSBFIRST, dataArray[ppos01]);

        digitalWrite(latchPin, HIGH);


        if (ppos01>6){
           cylState = true; //Enable the light cycling for center LED runLED1f4
        }

        else

        {
           cylState = false;
        }

        if (ppos01>=10){
           ppos01=0;
           buttonState=LOW;
           cylState = false;

        }
        else
        {
           ppos01 = ppos01 + 1;
        }

       //Serial.println("runShift1f Current: " + String(currentMillis, DEC) +" Previous: " + String(previousMillis01, DEC) + " ppos: " + String(ppos01, DEC)+ " pposcount: " + String( sizeof (dataArray) / sizeof (dataArray[0]),DEC) + " Array: " + String(dataArray[ppos01], BIN));

        // save the last time you blinked the LED
        previousMillis01 = currentMillis;
     }
}

//This is for the center "flash" LED
void runLED1f1()
{
   const unsigned long howLongToWait = 3; // Wait this many millis() "const" values can not be changed.
   static unsigned long lastChangeTime1; // last time the LED was turned on or off "static" references are available on the next run.

   int vals [] = { 0, 220, 150, 180, 190, 255 }; // brightness levels for the flash led
   int pwmIntervals = sizeof (vals) / sizeof (vals
  • );//6;   //number of values in array

   static int interval = 0; //which step are we on, starts at step 0 on the first run

   static int brightness; //holds the brightness value

   unsigned long ms = millis();

   if (buttonState==LOW) {
      interval = 0;
      }

   if (ms - lastChangeTime1 >= howLongToWait) {
      if (cylState) {
         interval = interval + 1;
      }
      else
      {
         brightness = 0;
      }
      lastChangeTime1 = ms;
      //Serial.println("interval: " + String(interval, DEC));
      if (interval >= pwmIntervals - 1)  {

         //interval = 0; //reset to 0 create an on going loop
         cylState = false;
      }
      else
      {
         brightness = vals[interval];
      }

   }

   if (cylState) {
      Serial.println("runLED1f1 Interval: " + String(interval , DEC) + " Brightness: " + String(brightness, DEC) + " pwmIntervals: " + String(pwmIntervals, DEC));
   }


   analogWrite(LED1,brightness);

}


//Just flashing another LED with the other button.
void runLED2(void)                          //**CHANGE the function name for each LED
{
    const unsigned long onTime = 900;     //**CHANGE the on and off times for each LED
    const unsigned long offTime = 500;
    static unsigned long lastChangeTime;    //last time the LED was turned on or off
    static boolean state = true;            //current LED state, true=on, false=off. start on

    unsigned long ms = millis();
    if (state) {    //LED on?
        if (ms - lastChangeTime >= onTime) {    //on long enough?
            state = false;                      //yes, set state to off
            lastChangeTime = ms;                //and record the time
        }
    }
    else { //LED is off
        if (ms - lastChangeTime >= offTime) {   //off long enough?
            state = true;                       //yes, set state to on
            lastChangeTime = ms;                //and record the time
        }
    }
    //set the LED's state
    digitalWrite(LED2, state);                  //**CHANGE the pin argument for each LED
}



« Last Edit: June 30, 2018, 02:30:45 pm by NMSquirrel »

 




Enterprise © Bloc