My code was working, now all the outputs are 1

So I have a robot that I made for class. It is meant to do like 4 things. Move forward and backward, be able to turn using a servo, turn on and off a laser, and be able to detect when the sensor is hit by a laser. It was for the most part working, is it pretty no but it was functional. The only thing that wasn't was the turning on and off the laser. I went to edit that code didn't work and when I tried again everything freaked out. So I disconnected the Arduino, got rid of that code and pull in the original code that I had saved elsewhere. However when I uploaded that to the Arduino it did the same thing it had before. After a bit of looking I figured out that everything was just reading as 1 and I don't know why. If anyone could help me figure it out and fix it I would greatly appreciate that. Also this is my first time using the forum so if I am putting this in the wrong place please let me know.

#define weaponPin 7
#define speedPin1 29
#define speedPin2 31
#define enA 11
#define Ch1 8
#define Ch2 9
#define Ch3 10
#include <Servo.h>
Servo control;
int life_count = 30;
int red = 4;
int yellow = 5;
int green = 6;
#define sensorPin 3
#define servoPin 2
int pinvalue = 1;
int var1 = 0;


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

  pinMode(Ch1, INPUT);
  control.attach(servoPin);

  pinMode(speedPin1, OUTPUT);
  pinMode(speedPin2, OUTPUT);
  pinMode(enA,OUTPUT);
  pinMode(Ch2, INPUT);

  pinMode(weaponPin, OUTPUT);
  pinMode(Ch3, INPUT);
 
  pinMode(sensorPin, INPUT);
  pinMode(red, OUTPUT);
  pinMode(yellow, OUTPUT);
  pinMode(green, OUTPUT);
 



}

void loop() {
  pinvalue = digitalRead(sensorPin);
 if(pinvalue == 1 && var1 == 0){
  (life_count = life_count - 10);
  var1 = 1;
   }else if(pinvalue == 0 && var1 == 1){
    var1 = 0;
    (life_count = life_count);
   }
 switch(life_count){
  case 30:
  digitalWrite(red, HIGH);
  digitalWrite(yellow, HIGH);
  digitalWrite(green, HIGH);
  break;
 case 20:
  digitalWrite(red, HIGH);
  digitalWrite(yellow, HIGH);
  digitalWrite(green, LOW);
  break;
 case 10:
  digitalWrite(red, HIGH);
  digitalWrite(yellow, LOW);
  digitalWrite(green, LOW);
  break;
 case 0:
  digitalWrite(red, LOW);
  digitalWrite(yellow, LOW);
  digitalWrite(green, LOW);
  break;
  default:
  break;
 }
int wheel= (Ch1, HIGH);
//Serial.print(wheel);
int wheel_new= map(wheel, 1120, 1980, 180, 0);
control.write(wheel_new);

int trigger= (Ch2, HIGH);
if(trigger <= 1450){
  analogWrite(enA,155);
  digitalWrite(speedPin1, LOW);
  digitalWrite(speedPin2, HIGH);
}else if(trigger >= 1550){
  analogWrite(enA,155);
  digitalWrite(speedPin1, HIGH);
  digitalWrite(speedPin2, LOW);
}else if(trigger <=1550 && trigger >= 1450){
  analogWrite(enA,0);
  digitalWrite(speedPin1, LOW);
  digitalWrite(speedPin2, LOW);
}
//Serial.println(trigger);

  int button= (Ch3, HIGH);
  Serial.println(button);
  int new_button= map(button, 600, 1600, 0, 1);
 
  if(digitalRead(new_button)== HIGH){
    digitalWrite(weaponPin, HIGH);
  }else(digitalRead(new_button)== LOW);{
  digitalWrite(weaponPin, LOW);
 }
 
 
 //Serial.println(pinvalue);
}

Hi @mrsrebel2 welcome to the forum.

You might want to look at this How to get the best out of this forum before you proceed any further.
We only know what you tell us, and without knowing what you have, we don't stand a chance.

Most of all we need to see a schematic, hand drawn is fine, physical layout diagrams are not very helpful.

Have you been changing the wiring of your project while it is powered up? That is the best way to fry your Arduino.

This may not do what you expect.

Hi, thank you for letting me know, it might take me a little bit to get an accurate schematic as before any of the code that was posted was finished and tested, it got changed a bit to fit the code so I am sorry but you might have to wait on that. However none of the of the wires have been changed. If you think it would be helpful I can take a picture of the robot, however I warn you it looks like a mess

  • Then clean it up . . .

This was the correct place to look, though i had to figure out what the problem was. Thank you for pointing me in the right direction. I needed to change it to int wheel= pulseIn(Ch1, HIGH); I had changed it out of this previously and it had continued to work so I thought it was ok, it was not

OK. I see now. It was bad luck that it still compiled even though the function name was missing. It left a construct behind with the "C++ comma operator" which hardly anyone uses except in the most contrived use cases. Thanks for reporting back.

Incidentally, this also appears unnecessary:

presumably you've overcome your problem, is the above correct, or should it be

  }
  else if (digitalRead (new_button) == LOW)  {
      digitalWrite (weaponPin, LOW);
  }