How do I attach files to my code?

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
dastels
 
Posts: 15659
Joined: Tue Oct 20, 2015 3:22 pm

Re: How do I attach files to my code?

Post by dastels »

It looks like for the "bad" one that the board is getting reset before (or when) setup() finishes. The output is from setup() And there's none from loop().

What are you powering it with? At the end of setup() you make the servos run. If you can't supply enough current it might be browning out and resetting.

Dave

User avatar
animefruit
 
Posts: 332
Joined: Tue Feb 25, 2020 1:04 pm

Re: How do I attach files to my code?

Post by animefruit »

I am powering it with my computer.

It is the easiest way to supply power when uploading?

Is that a problem to use that as a power source?

User avatar
animefruit
 
Posts: 332
Joined: Tue Feb 25, 2020 1:04 pm

Re: How do I attach files to my code?

Post by animefruit »

Wait.

I got it to kind of work.

But this code makes it to where the servo thinks the Button is pressed when it is not.

So the servo moves when the Button is pressed.

Can you tell me how to make it to where it Doesn't think the Button is being pressed when I am Not pressing it?

I have an image of how the Serial Monitor looks like attached to this post.

The Serial Monitor is "Sending Button #B" when it is Not being pressed.

Here is the code:

Code: Select all

  //#include <Servo.h>
#include <PWMServo.h>

#include "Adafruit_LiquidCrystal.h"


//ADD OF B START

#include <SPI.h>
#include <RH_RF69.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

 
#define LED 13// FOR LED


#define RF69_FREQ 434.0
/************ OLED Setup ***************/
Adafruit_SSD1306 oled = Adafruit_SSD1306();

#if defined(ESP8266)
  #define BUTTON_A 0
  #define BUTTON_B 16
  #define BUTTON_C 2
  #define LED      0
#elif defined(ESP32)
  #define BUTTON_A 15
  #define BUTTON_B 32
  #define BUTTON_C 14
  #define LED      13
#elif defined(ARDUINO_STM32F2_FEATHER)
  #define BUTTON_A PA15
  #define BUTTON_B PC7
  #define BUTTON_C PC5
  #define LED PB5
#elif defined(TEENSYDUINO)
  #define BUTTON_A 4
  #define BUTTON_B 3
  #define BUTTON_C 8
  #define LED 13
#elif defined(ARDUINO_NRF52832_FEATHER)
  #define BUTTON_A 31
  #define BUTTON_B 30
  #define BUTTON_C 27
  #define LED 17
#else // 32u4, M0, and 328p
  #define BUTTON_A 9
  #define BUTTON_B 6
  #define BUTTON_C 5
  #define LED      13
#endif


/************ Radio Setup ***************/

// Change to 434.0 or other frequency, must match RX's freq!
//#define RF69_FREQ 915.0
#define RF69_FREQ 434.0
#if defined (__AVR_ATmega32U4__) // Feather 32u4 w/Radio
  #define RFM69_CS      8
  #define RFM69_INT     7
  #define RFM69_RST     4
#endif

#if defined(ARDUINO_SAMD_FEATHER_M0) // Feather M0 w/Radio
  #define RFM69_CS      8
  #define RFM69_INT     3
  #define RFM69_RST     4
#endif

#if defined (__AVR_ATmega328P__)  // Feather 328P w/wing
  #define RFM69_INT     3  // 
  #define RFM69_CS      4  //
  #define RFM69_RST     2  // "A"
#endif

#if defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S2) || defined(ARDUINO_NRF52840_FEATHER) || defined(ARDUINO_NRF52840_FEATHER_SENSE)
  #define RFM69_INT     9  // "A"
  #define RFM69_CS      10  // "B"
  #define RFM69_RST     11  // "C"
  #define LED           13

#elif defined(ESP32)    // ESP32 feather w/wing
  #define RFM69_RST     13   // same as LED
  #define RFM69_CS      33   // "B"
  #define RFM69_INT     27   // "A"
#endif

#if defined(ARDUINO_NRF52832_FEATHER)
  /* nRF52832 feather w/wing */
  #define RFM69_RST     7   // "A"
  #define RFM69_CS      11   // "B"
  #define RFM69_INT     31   // "C"
  #define LED           17
#endif

// Singleton instance of the radio driver
RH_RF69 rf69(RFM69_CS, RFM69_INT);

//ADD OF B END

Adafruit_LiquidCrystal lcd(0);
 
PWMServo myservo1; //THE BIG CHANGE MARK MADE
PWMServo myservo2; //THE BIG CHANGE MARK MADE


 /*
//cant do A4 and A5(they are for lcd)
// Analogs 0 to 5
const int knockSensor = A0;
const int knockSensor1= A1;
const int knockSensor2= A2;
const int knockSensor3= A3;
const int knockSensor4= A6;
const int knockSensor5= A7;
 
 
const int threshold = 10;
int health = 500;
 
// 6 total sensor readings (from 0 to 5)
 
int sensorReading = 0;
int sensorReading1 =0;
int sensorReading2 =0;
int sensorReading3 =0;
int sensorReading4 =0;
int sensorReading5 =0;
 */
 
int pos =0;
 
 
 
//int deaths=1;// gonna be number of deaths
 
 
 
void setup()
 
{
 // pinMode(LED_BUILTIN, OUTPUT); //LED ON ARDUINO
  pinMode(LED, OUTPUT);//FOR LED
 
  Serial.begin(115200);//was 9600
 // Serial.println("Nerf Target v0.0.1, github.com/mcoms/nerf-target, 2014.");

 // pinMode(BUTTON_A, INPUT_PULLUP);
  pinMode(BUTTON_B, INPUT_PULLUP);
 // pinMode(BUTTON_C, INPUT_PULLUP);


  pinMode(LED, OUTPUT);    
  pinMode(RFM69_RST, OUTPUT);
  digitalWrite(RFM69_RST, LOW);

Serial.println("Feather RFM69 RX/TX Test!");

 
 // manual reset
  digitalWrite(RFM69_RST, HIGH);
  delay(10);
  digitalWrite(RFM69_RST, LOW);
  delay(10);
 
 
 
 
 if (!rf69.init()) {
    Serial.println("RFM69 radio init failed");
    while (1);
  }    // failed


 Serial.println("RFM69 radio init OK!");
  
  // Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM (for low power module)
  // No encryption
  if (!rf69.setFrequency(RF69_FREQ)) {
    Serial.println("setFrequency failed");
  }

  // If you are using a high power RF69 eg RFM69HW, you *must* set a Tx power with the
  // ishighpowermodule flag set like this:

rf69.setTxPower(14, true);

// The encryption key has to be the same as the one in the server
  uint8_t key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
                    0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
  rf69.setEncryptionKey(key);
  
  pinMode(LED, OUTPUT);

  //Serial.print("RFM69 radio @");  Serial.print((int)RF69_FREQ);  Serial.println(" MHz");
/*
  // OLED text display tests
  oled.setTextSize(2);
  oled.setTextColor(WHITE);
  oled.setCursor(0,0);
  oled.println("RFM69 @ ");
  oled.print((int)RF69_FREQ);
  oled.println(" MHz");
  oled.display();
*/
  delay(500);



 
// sg90
 
  lcd.begin (20 , 4);
  lcd.clear();
 
 
  Serial.begin(115200);
  myservo1.attach(9);
  myservo1.write(0);//was 0
 
  myservo2.attach(10);
  myservo2.write(45);//was 179
 
 
 
 
}
 
void loop()
{
 
 
 
 
  digitalWrite(LED_BUILTIN, HIGH);
  delay(2000);//was 2000             // FOR LED IN ARDUINO
  digitalWrite(LED_BUILTIN, LOW);
  delay(1000);
 
 
  /*
digitalWrite(LED, HIGH);
delay(2000);                 //FOR LED
digitalWrite(LED, HIGH);
delay(1000);
 */
 
 




 
 //lcd.setCursor(0, 2);
      //Serial.println(deaths); //showind number of deaths on the lcd
      //lcd.println(deaths);
 
 
//deaths= deaths + 1;// adding deaths
 
 //Start of Radio Sending Message
 
 {  if (rf69.waitAvailableTimeout(100)) {
    // Should be a message for us now  
    uint8_t buf[RH_RF69_MAX_MESSAGE_LEN];
    uint8_t len = sizeof(buf);
   
   if (! rf69.recv(buf , & len )) {
      Serial.println("Receive failed");
      return;
    }
    digitalWrite(LED, HIGH);
    rf69.printBuffer("Received: ", buf, len);
    buf[len] = 0;
   
    Serial.print("Got: "); Serial.println((char*) buf);
    Serial.print("RSSI: "); Serial.println(rf69.lastRssi(), DEC);

    oled.clearDisplay();
    oled.setCursor(0,0);
    oled.println((char*)buf);
    oled.print("RSSI: "); oled.print(rf69.lastRssi());
    oled.display(); 
    digitalWrite(LED, LOW);


    
  }


  //if (!digitalRead(BUTTON_A) || !digitalRead(BUTTON_B) || !digitalRead(BUTTON_C))

  if (!digitalRead(BUTTON_B) )
  {
    Serial.println("Button pressed!");
    
    char radiopacket[20] = "Button #";
    //if (!digitalRead(BUTTON_A)) radiopacket[8] = 'A';
    if (!digitalRead(BUTTON_B)) radiopacket[8] = 'B';
    //if (!digitalRead(BUTTON_C)) radiopacket[8] = 'C';
    radiopacket[9] = 0;

    Serial.print("Sending "); Serial.println(radiopacket);
    rf69.send((uint8_t *)radiopacket, strlen(radiopacket));
    rf69.waitPacketSent();




 myservo1.attach(9);
  myservo2.attach(10);
 
  delay(15);
 //Servo Starts Moving Here
 for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo1.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15 ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo1.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);    // waits 15 ms for the servo to reach the position
 
 //Servo Stops Moving Here
  }






 
 delay(1000);




 
  


  //delay(5000);
}
 }
}
    
Attachments
False Button.PNG
False Button.PNG (8.69 KiB) Viewed 183 times

User avatar
dastels
 
Posts: 15659
Joined: Tue Oct 20, 2015 3:22 pm

Re: How do I attach files to my code?

Post by dastels »

Let's talk about the hardware a bit. What are your buttons and how are they connected?

Dave

User avatar
animefruit
 
Posts: 332
Joined: Tue Feb 25, 2020 1:04 pm

Re: How do I attach files to my code?

Post by animefruit »

I am connecting my buttons normally like from the diagram attached.

My button switches are in a regular breadboard connected to my soldered breadboard.

There is a picture of my breadboards connected together attached to this post.

I also have an image of that attached.

I doubt that is the problem though because “Button B ” in the code works perfectly if I just use the RadioTXRX_Raw_OLED example.
Attachments
5FC1AC12-357C-480F-92D3-BACCCFB91535.jpeg
5FC1AC12-357C-480F-92D3-BACCCFB91535.jpeg (54.83 KiB) Viewed 172 times
B7688E65-1AD7-4644-94B5-A500F0A68711.jpeg
B7688E65-1AD7-4644-94B5-A500F0A68711.jpeg (538.22 KiB) Viewed 172 times

User avatar
dastels
 
Posts: 15659
Joined: Tue Oct 20, 2015 3:22 pm

Re: How do I attach files to my code?

Post by dastels »

You're button wiring is far more complex than it needs to be. All you need to do is connect one side of the button to ground and the other to the digital input on the Arduino. In the code you are setting the mode to INPUT_PULLUP. That means that the input is usually HIGH, and when you push the switch it gets connected to ground and is LOW.

Dave

User avatar
animefruit
 
Posts: 332
Joined: Tue Feb 25, 2020 1:04 pm

Re: How do I attach files to my code?

Post by animefruit »

I tried to do what you said.
But when I redid my buttons I don't think the Serial Monitor saying if I pressed something.
The code I use was the example code RadioHea69_RawDemoTXRX_OLED.
I connected one side of each button to the digital pin and the ground.
The digital pin I used on both was digital pin 9.
Attached to this post is the Seriel Monitor that didn't say that I pressed something.
Can you tell me how to fix this so that the Serial Monitor goes back to the way it was?
Attachments
Buttons Dont Work.PNG
Buttons Dont Work.PNG (15.17 KiB) Viewed 152 times

User avatar
animefruit
 
Posts: 332
Joined: Tue Feb 25, 2020 1:04 pm

Re: How do I attach files to my code?

Post by animefruit »

I just moved the Ground and Digital Pin Wires for my Buttons and Now it works better,
It displays what is pressed but still doesn't display anything when I press the button.
Can you tell me how to fix this problem?
I have a image of the improved Serial Monitor attached to this post.
Attachments
Button Works Better.PNG
Button Works Better.PNG (16.27 KiB) Viewed 150 times

User avatar
dastels
 
Posts: 15659
Joined: Tue Oct 20, 2015 3:22 pm

Re: How do I attach files to my code?

Post by dastels »

Are your buttons connected using diagonally opposite corners? See https://learn.adafruit.com/adafruit-ard ... tal-inputs.

Dave

User avatar
animefruit
 
Posts: 332
Joined: Tue Feb 25, 2020 1:04 pm

Re: How do I attach files to my code?

Post by animefruit »

I didn’t do it diagonally different.

But I did put them both on opposite sides of the button.


If I try to do it diagonally the Serial Monitor doesn’t display what is pressed.

I have picture of how it is connected attached to this post.
The black wire is GND and the yellow is the Digital Pin.

But now that the other button and Nano is using the digital pin 6 and the other button and Nano is using digital pin 9, it is now printing off both A and B in the Serial Monitor.

So that means it now it senses through the Radio that the other button is connected to the other Nano is connected to a different digital pin!
So that’s good!

I have a picture of the Serial Monitor attached to the post.

But now I need to figure out how to make it only display the other button when it is pressed.

Can you tell me how to do that?
Attachments
6F1769BB-A900-4EDA-A63A-D70B7C364690.jpeg
6F1769BB-A900-4EDA-A63A-D70B7C364690.jpeg (445.31 KiB) Viewed 144 times
0FB250D3-F0DB-4EBD-ABE6-0089C8258E0F.jpeg
0FB250D3-F0DB-4EBD-ABE6-0089C8258E0F.jpeg (264.31 KiB) Viewed 144 times

User avatar
dastels
 
Posts: 15659
Joined: Tue Oct 20, 2015 3:22 pm

Re: How do I attach files to my code?

Post by dastels »

Why do you have a resistor there?

Dave

User avatar
animefruit
 
Posts: 332
Joined: Tue Feb 25, 2020 1:04 pm

Re: How do I attach files to my code?

Post by animefruit »

The diagram I posted above and attached to this post says to have to use a resistor there.

Also. I fixed the problem by connecting the 5v and adding back all 3 buttons. It now works like it has been.

Now I just need to adjust my code so that when I press the button the servo moves rather than it moving when I don’t press the button.

Can you tell me how I can do that?

Here is my code:

Code: Select all

    //#include <Servo.h>
#include <PWMServo.h>

#include "Adafruit_LiquidCrystal.h"


//ADD OF B START

#include <SPI.h>
#include <RH_RF69.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

 
#define LED 13// FOR LED


#define RF69_FREQ 434.0
/************ OLED Setup ***************/
Adafruit_SSD1306 oled = Adafruit_SSD1306();

#if defined(ESP8266)
  #define BUTTON_A 0
  #define BUTTON_B 16
  #define BUTTON_C 2
  #define LED      0
#elif defined(ESP32)
  #define BUTTON_A 15
  #define BUTTON_B 32
  #define BUTTON_C 14
  #define LED      13
#elif defined(ARDUINO_STM32F2_FEATHER)
  #define BUTTON_A PA15
  #define BUTTON_B PC7
  #define BUTTON_C PC5
  #define LED PB5
#elif defined(TEENSYDUINO)
  #define BUTTON_A 4
  #define BUTTON_B 3
  #define BUTTON_C 8
  #define LED 13
#elif defined(ARDUINO_NRF52832_FEATHER)
  #define BUTTON_A 31
  #define BUTTON_B 30
  #define BUTTON_C 27
  #define LED 17
#else // 32u4, M0, and 328p
  #define BUTTON_A 9
  #define BUTTON_B 6
  #define BUTTON_C 5
  #define LED      13
#endif


/************ Radio Setup ***************/

// Change to 434.0 or other frequency, must match RX's freq!
//#define RF69_FREQ 915.0
#define RF69_FREQ 434.0
#if defined (__AVR_ATmega32U4__) // Feather 32u4 w/Radio
  #define RFM69_CS      8
  #define RFM69_INT     7
  #define RFM69_RST     4
#endif

#if defined(ARDUINO_SAMD_FEATHER_M0) // Feather M0 w/Radio
  #define RFM69_CS      8
  #define RFM69_INT     3
  #define RFM69_RST     4
#endif

#if defined (__AVR_ATmega328P__)  // Feather 328P w/wing
  #define RFM69_INT     3  // 
  #define RFM69_CS      4  //
  #define RFM69_RST     2  // "A"
#endif

#if defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S2) || defined(ARDUINO_NRF52840_FEATHER) || defined(ARDUINO_NRF52840_FEATHER_SENSE)
  #define RFM69_INT     9  // "A"
  #define RFM69_CS      10  // "B"
  #define RFM69_RST     11  // "C"
  #define LED           13

#elif defined(ESP32)    // ESP32 feather w/wing
  #define RFM69_RST     13   // same as LED
  #define RFM69_CS      33   // "B"
  #define RFM69_INT     27   // "A"
#endif

#if defined(ARDUINO_NRF52832_FEATHER)
  /* nRF52832 feather w/wing */
  #define RFM69_RST     7   // "A"
  #define RFM69_CS      11   // "B"
  #define RFM69_INT     31   // "C"
  #define LED           17
#endif

// Singleton instance of the radio driver
RH_RF69 rf69(RFM69_CS, RFM69_INT);

//ADD OF B END

Adafruit_LiquidCrystal lcd(0);
 
PWMServo myservo1; //THE BIG CHANGE MARK MADE
PWMServo myservo2; //THE BIG CHANGE MARK MADE


 /*
//cant do A4 and A5(they are for lcd)
// Analogs 0 to 5
const int knockSensor = A0;
const int knockSensor1= A1;
const int knockSensor2= A2;
const int knockSensor3= A3;
const int knockSensor4= A6;
const int knockSensor5= A7;
 
 
const int threshold = 10;
int health = 500;
 
// 6 total sensor readings (from 0 to 5)
 
int sensorReading = 0;
int sensorReading1 =0;
int sensorReading2 =0;
int sensorReading3 =0;
int sensorReading4 =0;
int sensorReading5 =0;
 */
 
int pos =0;
 
 
 
//int deaths=1;// gonna be number of deaths
 
 
 
void setup()
 
{
 // pinMode(LED_BUILTIN, OUTPUT); //LED ON ARDUINO
  pinMode(LED, OUTPUT);//FOR LED
 
  Serial.begin(115200);//was 9600
 // Serial.println("Nerf Target v0.0.1, github.com/mcoms/nerf-target, 2014.");

 // pinMode(BUTTON_A, INPUT_PULLUP);
  pinMode(BUTTON_B, INPUT_PULLUP);
 // pinMode(BUTTON_C, INPUT_PULLUP);


  pinMode(LED, OUTPUT);    
  pinMode(RFM69_RST, OUTPUT);
  digitalWrite(RFM69_RST, LOW);

Serial.println("Feather RFM69 RX/TX Test!");

 
 // manual reset
  digitalWrite(RFM69_RST, HIGH);
  delay(10);
  digitalWrite(RFM69_RST, LOW);
  delay(10);
 
 
 
 
 if (!rf69.init()) {
    Serial.println("RFM69 radio init failed");
    while (1);
  }    // failed


 Serial.println("RFM69 radio init OK!");
  
  // Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM (for low power module)
  // No encryption
  if (!rf69.setFrequency(RF69_FREQ)) {
    Serial.println("setFrequency failed");
  }

  // If you are using a high power RF69 eg RFM69HW, you *must* set a Tx power with the
  // ishighpowermodule flag set like this:

rf69.setTxPower(14, true);

// The encryption key has to be the same as the one in the server
  uint8_t key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
                    0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
  rf69.setEncryptionKey(key);
  
  pinMode(LED, OUTPUT);

  //Serial.print("RFM69 radio @");  Serial.print((int)RF69_FREQ);  Serial.println(" MHz");
/*
  // OLED text display tests
  oled.setTextSize(2);
  oled.setTextColor(WHITE);
  oled.setCursor(0,0);
  oled.println("RFM69 @ ");
  oled.print((int)RF69_FREQ);
  oled.println(" MHz");
  oled.display();
*/
  delay(500);



 
// sg90
 
  lcd.begin (20 , 4);
  lcd.clear();
 
 
  Serial.begin(115200);
  myservo1.attach(9);
  myservo1.write(0);//was 0
 
  myservo2.attach(10);
  myservo2.write(45);//was 179
 
 
 
 
}
 
void loop()
{
 
 
 
 
  digitalWrite(LED_BUILTIN, HIGH);
  delay(2000);//was 2000             // FOR LED IN ARDUINO
  digitalWrite(LED_BUILTIN, LOW);
  delay(1000);
 
 
  /*
digitalWrite(LED, HIGH);
delay(2000);                 //FOR LED
digitalWrite(LED, HIGH);
delay(1000);
 */
 
 




 
 //lcd.setCursor(0, 2);
      //Serial.println(deaths); //showind number of deaths on the lcd
      //lcd.println(deaths);
 
 
//deaths= deaths + 1;// adding deaths
 
 //Start of Radio Sending Message
 
 {  if (rf69.waitAvailableTimeout(100)) {
    // Should be a message for us now  
    uint8_t buf[RH_RF69_MAX_MESSAGE_LEN];
    uint8_t len = sizeof(buf);
   
   if (! rf69.recv(buf , & len )) {
      Serial.println("Receive failed");
      return;
    }
    digitalWrite(LED, HIGH);
    rf69.printBuffer("Received: ", buf, len);
    buf[len] = 0;
   
    Serial.print("Got: "); Serial.println((char*) buf);
    Serial.print("RSSI: "); Serial.println(rf69.lastRssi(), DEC);

    oled.clearDisplay();
    oled.setCursor(0,0);
    oled.println((char*)buf);
    oled.print("RSSI: "); oled.print(rf69.lastRssi());
    oled.display(); 
    digitalWrite(LED, LOW);


    
  }


  //if (!digitalRead(BUTTON_A) || !digitalRead(BUTTON_B) || !digitalRead(BUTTON_C))

  if (!digitalRead(BUTTON_B) )
  {
    Serial.println("Button pressed!");
    
    char radiopacket[20] = "Button #";
    //if (!digitalRead(BUTTON_A)) radiopacket[8] = 'A';
    if (!digitalRead(BUTTON_B)) radiopacket[8] = 'B';
    //if (!digitalRead(BUTTON_C)) radiopacket[8] = 'C';
    radiopacket[9] = 0;

    Serial.print("Sending "); Serial.println(radiopacket);
    rf69.send((uint8_t *)radiopacket, strlen(radiopacket));
    rf69.waitPacketSent();




 myservo1.attach(9);
  myservo2.attach(10);
 
  delay(15);
 //Servo Starts Moving Here
 for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo1.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15 ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo1.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);    // waits 15 ms for the servo to reach the position
 
 //Servo Stops Moving Here
  }






 
 delay(1000);




 
  


  //delay(5000);
}
 }
}
    
    
Attachments
BDE680F7-E3E8-4114-9385-774E54C8BD2C.jpeg
BDE680F7-E3E8-4114-9385-774E54C8BD2C.jpeg (46.09 KiB) Viewed 132 times

User avatar
dastels
 
Posts: 15659
Joined: Tue Oct 20, 2015 3:22 pm

Re: How do I attach files to my code?

Post by dastels »

According to your code you have the button input set to INPUT_PULLUP. That means you want your button to connect the input to ground (i.e. LOW) when it's pressed. This is typical on these older MCUs that just had pullups on the inputs. In light of that, your button is wired wrong.

Remove the resistor and the 5v wires. Connect the button connection where the resistor is directly to ground. Now the input should normally be HIGH and will be LOW when pressed.

Double check your actual button. What EXACTLY is it. Link to a product page would be best. If it is one of these breadboardable buttons (e.g. https://www.adafruit.com/product/367) you have to use diagonally oppostire corners to be sure it's wired correctly. pair of connections are connected together internally. See toward the end of https://learn.adafruit.com/adafruit-ard ... ard-layout.

Dave

User avatar
animefruit
 
Posts: 332
Joined: Tue Feb 25, 2020 1:04 pm

Re: How do I attach files to my code?

Post by animefruit »

If I undo the 5V it does not work for whatever reason. But it works right now with 5v attached. Here’s my photos of both computers when I push opposite buttons attached to this post it says “Got:Button #B”. Now I just need to include the servo code so that the servo moves after I press the Button and then after that it should say “Got: Button #B” on the Seriel Monitor. Can you show me how to do that instead?

User avatar
dastels
 
Posts: 15659
Joined: Tue Oct 20, 2015 3:22 pm

Re: How do I attach files to my code?

Post by dastels »

Sorry, but I'm not here to write code for you. There are lots of projects at https://learn.adafruit.com/ that deal with buttons and servos.

Dave

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”