Embedded programming

This assignment was something new for me, as a Mechanical engineer designer i always believed another person who knows electronics and programming should be my arm when it comes to electronic and electronic systems. But sometimes it was always hard for developing a product because, this person doesn't understand what i mean or i dont understand how to do this programms. Now i m understanding everything. So i started with many problems, my fab ISP had problems because it was not recognized by the computer and i couldn't programm it, despite it had a green light when i connect it to de AVRisp. So i weld another one (my third fab ISP) and everything was correct. (By the way i m now expert welding this small superficial electronic boards).

Then I discovered Arduino software. This made things a bit more understandable. At least it gave me a visual refference on what I was supposed to do. It looked more like HTML-code with pretty colors and text explaining the commands and what they are supposed to do. Even with this setup it took me an hour or two to figure out how to use it. Eventually we had one LED light up. But it lit up whenever it liked and it almost looked like it was touch sensitive. After routing the current through the VCC the LED started to work like it should. Some tinkering in the commands further and now we had the red LED blink and the green only on when the red was not on. Adding the button in the software was simpler. We cheated using the basic sheets provided by Arduino and adding our own code to the sofware. Hey, it worked!

  • Download here the Data sheet

  • I programmed the chip with arduino

    CODE USED
    const int buttonPin = 3;
    const int ledPin1 = 2;
    const int ledPin2 = 4;
    
    int ledState1 = HIGH;
    int ledState2 = LOW;
    int buttonState;
    int lastButtonState = LOW;
    
    unsigned long lastDebounceTime = 0;
    unsigned long debounceDelay = 50;
    
    void setup() {
      pinMode(buttonPin, INPUT);
      pinMode(ledPin1, OUTPUT);
      pinMode(ledPin2, OUTPUT);
    
      digitalWrite(ledPin1, ledState1);
      digitalWrite(ledPin2, ledState2);
    }
    
    void loop() {
      int reading = digitalRead(buttonPin);
    
      if (reading != lastButtonState) {
        lastDebounceTime = millis();
      }
    
      if ((millis() - lastDebounceTime) > debounceDelay) {
        if (reading != buttonState) {
          buttonState = reading;
    
          if (buttonState == HIGH) {
            ledState1 = !ledState1;
            ledState2 = !ledState2;
          }
        }
      }
    
      digitalWrite(ledPin1, ledState1);
      digitalWrite(ledPin2, ledState2);
    
      lastButtonState = reading;
    }