Bräuche mal eue Hilfe beim Selbstbau einer Automatischen Treppenbeleuchtung

Also mal als erstes... dieses Forum ist der Hammer, nicht nur das Deutsche.
Um alles zu überfliegen braucht man mindestens 4 Wochen und um alles zu lesen vermutlich 4 Jahre. :grin:

Also die ersten Gehversuche (vielleicht besser Krabbeln) habe ich mit Arduino Uno und Pro Mini habe ich schon hinter mir, aber .............

Ich versuche wohl eine etwas älte Software in einen Pro Mini Upzuloaden, aber mit 2 Fehlermeldungen.

Gibt es jemanden der mir da helfen könnten um das Projekt ans laufen zubekommen? :blush:

/**
 *  Copyright (c) 2011, Erica S. Kane
 * 
 *  This code is based in part on the Lightuino open source project by G. Andrew Stone,
 *  available at: http://code.google.com/p/arduino-m5451-current-driver/
 *
 *  This software is licensed under the MIT Open License (http://www.opensource.org/licenses/mit-license.php)
 *
 *  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 
 *  associated documentation files (the "Software"), to deal in the Software without restriction, 
 *  including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
 *  and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 
 *  subject to the following conditions:
 *  
 *  The above copyright notice and this permission notice shall be included in all copies or substantial 
 *  portions of the Software.
 *
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT 
 *  LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
 *  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 
 *  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 
 *  SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 *  Erica S. Kane
 *  http://www.thekanes.org/
 *  http://www.thekanes.org/projects/automated-led-stairs
 */

#include <lightuino3.h>
#include <Ping.h>

// pins 0, 1 used by Serial
const unsigned char bottomPingInputPin = 5;
const unsigned char topPingInputPin = 8;
const unsigned char serDataPin1 = 6;
const unsigned char clockPin = 7;
const unsigned char ledPin =  13;    // Arduino LED connected to digital pin 13

// timing for light sequences (ms)
const long lightSpacing = 250;
const long lightHold = 10000;
const long pingReadDelay = 100;

Ping bottomPing = Ping(bottomPingInputPin, 0, 0);
Ping topPing = Ping(topPingInputPin, 0, 0);

// Distance triggers for Ping
const float minBottomIn = 30.0f;
const float minTopIn = minBottomIn;

// LightuinoSink(uint8_t clockPin=7,uint8_t serDataPin1=6,uint8_t serDataPin2=5,uint8_t brightPin=4);
LightuinoSink sinks(clockPin, serDataPin1, 100, 4);

boolean bClimbStarted = false;
boolean bDescentStarted = false;

void setup() {
  Serial.begin(9600);      
  
  pinMode(ledPin, OUTPUT);  
  pinMode(serDataPin1, OUTPUT);
  pinMode(clockPin, OUTPUT);    
  
  digitalWrite(ledPin, LOW); 

  delay(1000);
  Serial.print("Flags: ");
  Serial.println(sinks.flags);    
  
  sinks.set(0,0,0);
}

void loop() {
  // see if anyone has triggered the sensor on the bottom step
  checkBottomSensor();
  
  if(bClimbStarted) {
    bClimbStarted = false;
    bDescentStarted = false;
    Serial.println("Firing climbing sequence.");
    climbLightSequence(); 
  } 
  else {
    // see if anyone has triggered the sensor on the top step
    checkTopSensor();
    
    if(bDescentStarted) {
      bClimbStarted = false;
      bDescentStarted = false;
      Serial.println("Firing descent sequence.");
      descentLightSequence(); 
    } 
  }
  
  delay(pingReadDelay);
}

/**
 *  Looks to see if anyone has tripped the bottom sensor. If so, set a flag.
 */
void checkBottomSensor() {    
  bottomPing.fire();
  
  /**
   *  If the PING cannot "see" anything, the fire method can take a while
   *  as it waits for the echo. For continuous recording, it's best to have
   *  something outside the minimum so that the ultrasonic wave bounces back
   *  quickly.
   */
  
  if((bottomPing.inches() < minBottomIn) && (bottomPing.inches() > 0)) {
    Serial.println("Bottom sensor tripped.");
    bClimbStarted = true;
  }
}

/*
 *  Looks to see if anyone has tripped the bottom sensor. If so, set a flag.
 */
void checkTopSensor() {    
  topPing.fire();
  
  if((topPing.inches() < minTopIn) && (topPing.inches() > 0)) {
    Serial.println("Top sensor tripped.");
    bDescentStarted = true;
  }
}


/**
 *  Light pattern that fires when someone starts climbing the steps
 */
void climbLightSequence() {
  // You could put code in here to use other sequences of your design
  standardClimbSequence();
}

void standardClimbSequence() {
  Serial.println("climbLightSequence started.");
  byte ledState[9];
  for (int j=0;j<9;j++) {
    ledState[j] = B00000000;
  }
  
  /**
   *  ledState[1] controls pins 3 through 10 on the M4541.
   *  ledState[2] controls pin 2 and ...?
   *  ledState[0] controls pin 11 and ... ?
   */
  
  ledState[1] = B00000000;
  ledState[2] = B00000000;
  
  Serial.println("Turn on pin 11."); // bottom
  ledState[0] = B10000000;
  sinks.set(ledState);
  delay(lightSpacing);   
     
  Serial.println("  Turn on LEDs from pin 10 to pin 3 in sequence");
  // Each bit (1 or 0) in this array corresponds to one LED light
  for (int j=0; j < 9; j++) {        
    ledState[1] = (ledState[1] << 1) + 1;
    Serial.print("ledState[1] = ");
    Serial.println(ledState[1], BYTE);
        
    // Now send it to the chips.
    sinks.set(ledState);          
    delay(lightSpacing);
  }
       
  Serial.println("Turn on pin 2.");
  ledState[2] = B00000001;      
  sinks.set(ledState);   
  delay(lightSpacing);
        
  // Keep them lit for a while
  delay(lightHold);       
         
  // Serial.println("  Turn them all off!");  
  // sinks.set(0,0,0);
  
  // Now reverse the sequence
  Serial.println("Turn off pin 11."); // bottom
  ledState[0] = B00000000;
  sinks.set(ledState);
  delay(lightSpacing);   
  
  Serial.println("  Turn off LEDs from pin 10 to pin 3 in sequence");
  // Each bit (1 or 0) in this array corresponds to one LED light
  for (int j=0; j < 9; j++) {        
    ledState[1] = ledState[1] << 1;
    Serial.print("ledState[1] = ");
    Serial.println(ledState[1], BYTE);
        
    // Now send it to the chips.
    sinks.set(ledState);          
    delay(lightSpacing);
  }  
  
  Serial.println("Turn off pin 2."); // top
  ledState[2] = B00000000;      
  sinks.set(ledState);   
  delay(lightSpacing);
 }

/**
 *  Light pattern that fires when someone starts going down the steps
 */
void descentLightSequence() {
  // You could put code in here to use other sequences of your design
  standardDescentSequence();
}

void standardDescentSequence() {
  Serial.println("descentLightSequence started.");
  byte ledState[9];
  for (int j=0;j<9;j++) {
    ledState[j] = B00000000;
  }
  
  /**
   *  ledState[1] controls pins 3 through 10 on the M4541.
   *  ledState[2] controls pin 2 and ...?
   *  ledState[0] controls pin 11 and ... ?
   */
  
  ledState[1] = B00000000;
  ledState[2] = B00000000;
  
  Serial.println("Turn on pin 2.");
  ledState[2] = B00000001;      
  sinks.set(ledState);   
  delay(lightSpacing);
     
  Serial.println("  Turn on LEDs from pin 3 to pin 10 in sequence");
  // Each bit (1 or 0) in this array corresponds to one LED light
  for (int j=0; j < 9; j++) {        
    ledState[1] = (ledState[1] >> 1) + 128;
    Serial.print("ledState[1] = ");
    Serial.println(ledState[1], BYTE);
        
    // Now send it to the chips.
    sinks.set(ledState);          
    delay(lightSpacing);
  }

  Serial.println("Turn on pin 11.");
  ledState[0] = B10000000;
  sinks.set(ledState);
        
  // Keep them lit for a while
  delay(lightHold);       
         
  // Serial.println("  Turn them all off!");  
  // sinks.set(0,0,0);
  
  // Now reverse the sequence
  Serial.println("Turn off pin 2.");
  ledState[2] = B00000000;      
  sinks.set(ledState);   
  
  Serial.println("  Turn off  LEDs from pin 3 to pin 10 in sequence");
  // Each bit (1 or 0) in this array corresponds to one LED light
  for (int j=0; j < 9; j++) {        
    ledState[1] = ledState[1] >> 1;
    Serial.print("ledState[1] = ");
    Serial.println(ledState[1], BYTE);
        
    // Now send it to the chips.
    sinks.set(ledState);          
    delay(lightSpacing);
  }    

  Serial.println("Turn off pin 11.");
  ledState[0] = B00000000;
  sinks.set(ledState);
  delay(lightSpacing);                    
 }

Ich rate mal: die library ist noch für die Arduino-Version vor 1.0 geschrieben und sie liegt nicht im libraries-Ordner.
Die Änderungen in 1.0 sind in den sticky-Posts hier im Forum (FAQ Neuigkeiten und Probleme ab Arduino IDE 1.0)
Du kannst den Sketch aber z.B. mal mit einer Arduino 022 versuchen, wenn Du die library vorher im libraries-Ordner im Arduino Sketch-Verzeichnis abgelegt hast.

Hallo CFJoe,
der Sketch sieht mir auf Anhieb viel zu aufwendig aus.
Was ich dir anbieten könnte ist ein komplett fertiges Programm, welches wesentlich kürzer, einfacher und verständlicher ist.
Allerdings vermute ich mal das du einen Mega brauchst, da man doch ordentlich viele Pins für eine vernünftige Treppenlichtbeleuchtung benötigt.
Gruß
Bernward

Hallo,

vielen Dank für die Hilfe. Es war ein Libary fehler. Erläutere für kommende oder verfolgende Gäste mein Vorgehen im Anhang.

Habe es jetzt mit einer 022 Version zum laufen bekommen, allerdings -wie unerwartet- einen neuen Fehler.
Code wird allerdings soweit sauber kompiliert, Fehler entsteht beim übertragen:

avrdude: stk500_getsync(): not in sync: resp=0x00
avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x51

Da hoffe ich das die Erfahreneren in zusammenhang mit dem Quellcode von oben der sich nicht geändert hat etwas anfangen können.

Vielen Dank.
Joe

Anhang:

Ich musste die 2 gebrauchten Librarys lightuino3.h und Ping.h suchen bzw. finden.
Bei lightuino3.h war das relativ einfach, da der Ersteller des Codes auch diese Library zur Verfügung gestellt hat. Auch wenn es erst verwirrend war das der Ordner selber lightuino5 hieß, aber 3 scheint dort wohl inbegirffen. Es lief.

Ping.h habe ich mir aus dem Netz besorgt. Das Problem war nur das er unter der Arduinoversion 022 natürlich nichts mit #include Arduino.h anfangen konnte( siehe auch 'Änderungen zu Arduino 1.0' http://arduino.cc/forum/index.php/topic,127552.0.html).
Da allerdings der dort angebene Quellcode keine Hilfe brachte, habe ich dann die includes der Ping Library(Ping.h und Ping.cpp) von Arduino.h auf WProgram.h händisch geändert.

Danach wurde alles Fehlerfrei kompiliert unter der Arduinoversion 022.

Edith meint noch:
Wenn ich versuche das ganze unter Arduino 1.0 laufen zulassen, geht es auch nur mit modifizierter Ping.h. Allerding bekomme ich dann folgenden Fehler schon beim kompilieren:

Seit Arduino 1.0 wird das Keyword 'BYTE' nicht mehr unterstützt.
Bitte verwenden Sie stattdessen Serial.write().

Wie soll ich allerdings ein Attribut vom Datentyp byte, welches im Code verändert wird mit Serial.write() umschreiben?
Da wäre vielleicht dein Code ganz interessant maverick1509. Würde mir das Programm gerne ansehen.

Seit Arduino 1.0 wird das Keyword 'BYTE' nicht mehr unterstützt.

Meinst du nicht statt BYTE eher BIN ?
aus Serial.print() - Arduino Reference :

Serial.print(78, BIN) gives "1001110"

In deinem Fall

  for (int j=0; j < 9; j++) {        
    ledState[1] = (ledState[1] << 1) + 1;
    Serial.print("ledState[1] = ");
    Serial.println(ledState[1], BIN);
   // ...
    delay(250);

liefert das 9 (warum brauchst du das ?) Zeilen

ledState[1] = 1
ledState[1] = 11
ledState[1] = 111
ledState[1] = 1111
ledState[1] = 11111
ledState[1] = 111111
ledState[1] = 1111111
ledState[1] = 11111111
ledState[1] = 11111111