Did my code destroy the arduino?

Hi comunity. I am a beginner. I work on this code for a long time and receive already help. the code isnt done nor perfect. I play with it and upload it on and on. Now i didnt tinker with it since one week, and i dont remember what i did last time to make my arduino failing now... I did plug it into the pc´s usb and the the tx light is blinking very fast. when i try to upload any code its says in the IDE access denied or port busy.
I tried another arduino, it worked, i was able to upload the code, but then the same happened. luckily the 2nd board stopped at some time the blinking and i was able to upload any other code. however, the first arduino keeps blinking and i dont have access anymore. did i shot my arduino form the code???

EDIT: I just closed all opened IDE´s on my computer. problem fixed, arduino works...
New experience, never happened. can anyone explain the issue?

#include <LiquidCrystal_I2C.h> //from new ldc
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 20 chars and 4 line display, without that characters cant be set to specific lines at specific places

//stage 2 after buttonsystemonoff and lcd setup - beginn
#include <IRLibSendBase.h> //from new sucessful code from internet, this is the base
#include <IRLib_P01_NEC.h> //from new sucessful code from internet, this is the actual protocol
//IRsend mySender; //from new sucessful code from internet, no idea how that matters
#include <DallasTemperature.h> //library from temp sensor 18b20
#include <OneWire.h> //library communication from temp sensor 18b20
// Data wire is plugged into pin 2 on the Arduino //im not sure about that, had to tinker and
#define ONE_WIRE_BUS 2 // when plugged data wire in pin 2 and opened serial mon. temp came in...
// Pass our oneWire reference to Dallas Temperature.
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

float settemp=25;
float settemphyst;
int ledforactualcooling=12; //the blue LED under the display
int buttondown=8;
int buttonup=10;
//stage 2 after buttonsystemonoff and lcd setup - end

const int buttonsystemonoff = 9; // the number of the pushbutton pin

int storedState; // not sure what that actually does in the code
int Thermostatstate = LOW; // needed for debouncing
int lastButtonState = HIGH; // needed for debouncing
int currentstate; // needed for debouncing
long lastDebounceTime = 0; // the last time the output pin was toggled
long debounceDelay = 100; // the debounce time; increase if the output flickers

void setup() // SETUP SETUP SETUP SETUP SETUP SETUP SETUP SETUP SETUP SETUP SETUP SETUP SETUP SETUP SETUP SETUP SETUP SETUP
{
//stage 2 after buttonsystemonoff and lcd setup - beginn
pinMode(LED_BUILTIN, OUTPUT); // internal board LED for showing systembuttonon/off state(same state as shown in display)
sensors.begin(); //from temp sensor 18b20
pinMode(buttondown, INPUT);
pinMode(buttonup, INPUT);
pinMode(ledforactualcooling,OUTPUT);
//stage 2 after buttonsystemonoff and lcd setup - end

pinMode(buttonsystemonoff, INPUT);
Serial.begin(9600); // start serial communication to Pc program
lcd.begin(); // initialize the lcd
lcd.print("Hello guys");
lcd.setCursor(0, 1);
lcd.print("my Invention");
delay(2000);
lcd.clear();

lcd.print("Swamp Cooler");
lcd.setCursor(0, 1);
lcd.print("Thermostat");
lcd.setCursor(0, 2);
lcd.print("Room T.");
lcd.setCursor(19, 2);
lcd.print("C");
lcd.setCursor(0, 3);
lcd.print("Set T.");
lcd.setCursor(11, 2);
lcd.print("C /");
lcd.setCursor(19, 2);
lcd.print("F");
}
void loop() // LOOP LOOP LOOP LOOP LOOP LOOP LOOP LOOP LOOP LOOP LOOP LOOP LOOP LOOP LOOP LOOP LOOP LOOP LOOP LOOP LOOP LOOP LOOP LOOP LOOP
{
sensors.requestTemperatures(); // !!!!!!!!found for very first time issue of code: this request temp. slows all buttons down!!!

currentstate = digitalRead(buttonsystemonoff); // my own new interpretation of these three lines of code:
if (currentstate != lastButtonState) { // button state just changed and still bounces over and over, (lastButtonState = currentState)
lastDebounceTime = millis(); // keeps changing. both ongoing until it settles. then, we need the following 2nd action to make final comparison to inital state
lastButtonState = currentstate;
}
if ((millis() - lastDebounceTime) > debounceDelay) { //debounce thermostat on/off button and write status in LCD
if (Thermostatstate != lastButtonState) {
Thermostatstate = lastButtonState;
if (Thermostatstate == HIGH) {
storedState = !storedState; //for now i assume the thermostat on/off button turned into a storedstate
//digitalWrite(LED_BUILTIN, HIGH);
lcd.setCursor(16,1); // this here clears the "OFF" writing from prior, written in storedState==low
lcd.print(" "); // interesting: had in prior code the whole line written, so in loop the word thermostatstate was also refreshed
lcd.setCursor(16,1); // since this is different: whenever off will be written, it now changes AFTER releasing the button... = )
lcd.print("ON");
}
else{if (storedState==LOW){
//digitalWrite(LED_BUILTIN, LOW);
lcd.setCursor(16,1);
lcd.print("OFF");
}
}
}
}
//stage 3 button up and down settemp - beginn

if(digitalRead(buttonup)== 1 ) { // if we se the switch reading on 1 or 5 volts
settemp ++; // add one to the settemp, the settemp is the ideal temperature for you
}
else{// other wise do nothing
}

if(digitalRead(buttondown)== 1 ){ // if we se the switch reading on 1 or 5 volts
settemp --; // add one to the settemp, the settemp is the ideal temperature for you
}
else{// other wise do nothing
}
//stage 3 button up and down settemp - end

//stage 4 print temps and settemps - beginn

lcd.setCursor(7,3);
lcd.print (settemp,0); //behind the comma means number of digits behind comma shown on lCD
lcd.setCursor(11,3);
lcd.print ("C / ");
lcd.print(settemp*1.8+32,0); //behind the comma means number of digits behind comma shown on lCD
lcd.setCursor(19,3);
lcd.print("F");

lcd.setCursor(7, 2);
lcd.print(sensors.getTempCByIndex(0),1); //behind the comma means number of digits behind comma shown on lCD
lcd.setCursor(15, 2);
lcd.print(sensors.getTempCByIndex(0)*1.8+32,1); //behind the comma means number of digits behind comma shown on lCD

Serial.println(sensors.getTempCByIndex(0),1);
settemphyst = (settemp-1.5);
lcd.setCursor(14,0);
lcd.print (settemphyst,1);
//stage 4 print temps and settemps - end

//delay(30); // wired: i need this delay, otherwise when "off" is displayed on the lcd its flickering. ( if "on" displayed it doesnt flicker at all).
// downside of delay: now i need to push the button longer in order to make the arduino recogizing the button push. why ????
}

A connection stays active until terminated. As long as it exists any other connection attempt will fail.

One such "connection" is the Arduino IDE's Serial Monitor. The Arduino IDE is able to control its Serial Monitor to close the port before an upload, then open it again after, so this is not a common cause of a failed upload. However, if you open multiple instances of the Arduino IDE by starting it multiple times or opening multiple sketches directly, then one instance of the IDE is unable to control the Serial Monitor of the other instance and so you must manually close the Serial Monitor of one instance before uploading in the other.

Arduino IDE windows created via the File > New, File > Open, File > Sketchbook, or File > Examples menus are all of the same IDE instance and so are able to control the Serial Monitor as needed.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.