Please help. I'm new to C++ and code is not working

Hello,

I'm trying to write some C++ code to run a relay control board. It should be simple but it's working the opposite of what I thought I was telling C++ to do. There's one switch connected to PINB1. If it's high I don't want anything to happen. If it's low (or closed) I want it to execute turn on the relays in the sequence that follows. The sequence works but it's turning on when the switch is high instead of low. And when I initially power up the relay sequence runs through once no matter what the switch is set to? I'm confused by this. Any advise would be greatly appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
  #include <avr/io.h>
#include <util/delay.h>

 int main(void)
 {
   DDRB |= 1 << PINB2; // output turn on heater one
   DDRB |= 1 << PINB3; // output turn on fan one
   DDRB |= 1 << PINB4; // output turn on solenoid to switch containers
   DDRB |= 1 << PINB5; // output turn on heater two
   DDRB |= 1 << PINB6; // output turn on fan two
   DDRB |= 1 << PINB7; // spare output
   DDRB |= 1 << PINB0; // output turn on ozone gen
   DDRB |= 0 << PINB1; // vacuum switch
   PORTB |= 1 << PINB1; // set vacuum switch pin high or open
   int Pressed = 1;

   while (1)
  {
    if (bit_is_clear(PINB, 1))  // bit is clear means vacuum switch closed and grounded zero volts
	{
	 if (Pressed == 1)
	      {
	    PORTB = 0b00000011; // turn on ozone gen
		_delay_ms(1000);
		PORTB = 0b00000111; // turn on heater one
		_delay_ms(1000);
		PORTB = 0b00001111; // turn on fan one
		_delay_ms(1000);
		PORTB = 0b00000010; // turn everything off
		_delay_ms(1000);
		PORTB = 0b00010011; // switch container turn on ozone gen
		_delay_ms(1000);
		PORTB = 0b00110011; // now turn on heater two
		_delay_ms(1000);
		PORTB = 0b01110011; // turn on fan two
		_delay_ms(1000);
	   //PORTB |= 0 << PINB2;
	   //PORTB |= 1 << PINB0;
        PORTB = 0b00000000;
		Pressed = 0;
         }
		 }
     else
    {
	   PORTB = 0b00000000;
	   Pressed = 1;
	   //PORTB |= 0 << PINB0;
	   //PORTB |= 1 << PINB2;
      
    }
  }
}
Line 13 actually does nothing. 0 << PINB1 remains 0. So DDRB |= 0 changes nothing.
Topic archived. No new replies allowed.