Even my Teacher can't help me with our project!

Hello,

I became familiar with Arduino through a school project two weeks ago. My partner and I are currently working on a “shutter control”. As our code doesn’t work as it should and my teacher got no idea what we did wrong , we are asking you guys to help us.

What we got:

  • Arduino Uno
  • Stepper
  • Photoresistor
int eingang=A1;
// Analogport 1
int oben;
int unten=1;
int  rollo;

int sensorWert = 0;
#include <Stepper.h>

int SPMU = 32;  

Stepper myStepper(SPMU, 2,3,4,5); 
// 2,3,4,5, sind die Steckplätze          


void setup()
{
Serial.begin(9600);

myStepper.setSpeed(500);
}

void loop()
{
sensorWert=analogRead(eingang);

Serial.print("Sensorwert =");
Serial.println(sensorWert);


if(sensorWert<600)
{
int rollo = 0;

}
else
{
int rollo = 1;}


switch (unten) {
case 1:
        switch (rollo) {
        case 0:
	
	break;
        case 1:
        myStepper.step(2048);
        oben = 1;
        unten = 0;
        break;}
        
}
switch (oben) {
case 1:
        switch (rollo){
        case 0:
        myStepper.step(-2048);
        oben=0;
        unten=1;
	      break;
	      case 1:
        break;
	      }
        


}
}

What it should do:

Turn the blinds up if it’s bright outside and then stop doing anything until it’s dark again, when it should turn them back down.

Clarification

oben = up

unten = down

Sensorwert = sensor value

Thank you for your attention. Have a great day.

Greetings Lizraya

Look at the scope of all the variables called "rollo"

In your code:

if(sensorWert<600)
{
   int rollo = 0;             // rollo #1 comes to life here

} else {
   int rollo = 1;             // rollo #2 comes to life here

}         // When execution gets to this line, both rollo #1 and #2 die.

you have defined two version of rollo. However, both are defined within the if statement block. There is a C programming concept called scope that determines the life and visibility of a variable. Try changing your code to:

int rollo;

if(sensorWert<600)
{
   rollo = 0;             

} else {
   rollo = 1;             

}

and see what happens.

It worked ! But serously that was a silly mistake of mine.
I appreciate your quick help. I'm very thankful.

Greetings Lizraya

But serously that was a silly mistake of mine.

One that you are not likely to repeat, are you? A learning experience is a good thing.

lizraya:
and my teacher got no idea what we did wrong

Also a very valuable learning experience

...R