首页 > 解决方案 > 正面和负面的变化没有声明,它在之前的情况下非常高兴,同样的声明

问题描述

我们正在创建一个基于几个输入的 arduino 系统打开/关闭百叶窗

  1. 光传感器只能关闭百叶窗,即无法打开百叶窗
  2. 一个按钮,用于切换百叶窗处于打开或关闭的任何状态。我们用 pos 跟踪我们的 pos
#include <Stepper.h>
int buttonstate = 0;
void setup() {

  Stepper myStepper(stepsPerRevolution, 8, 10, 9, 11);
  Serial.begin(9600);
  //Speed is variable up 10, 11 starts to make issues
  myStepper.setSpeed(10); 
   const int stepsPerRevolution = 2048;
 const int button = 5;
  int pos = 2;
  int prevpos = 2;
  int idrread = 0;
  pinMode(button, INPUT);
  }

void loop() {
buttonstate = digitalRead(button);
idrread = analogRead(A7);

switch (buttonstate)
// sure if the && statements would work
  case (buttonstate == HIGH && pos == 2):
  myStepper.step(stepsPerRevolution);//change these lines to the correct steps for correct roation, or leave them for demonstaration 
  pos = 1;
  case (buttonstate == HIGH && pos ==1):

这是它在 -stepsPerRevolution 上绊倒的地方

  myStepper.step(-stepsPerRevolution);
  pos =2;
  
 // if the blinds are open and the sensor reads light on, close the blinds 
if (pos ==2 && idrread < 940/*can change as well as <,>*/){
  myStepper.step(stepsPerRevolution);
  pos = 1;
}
}

标签: arduino-c++

解决方案


推荐阅读