Arduino Coding - Tech W2
In our second workshop for Arduino, it was about the coding side of things and how to correctly write it as well as the different codes and functions that can be used. Variables and constants Void setup(), void loop() x() If, else if, while, for statements Always comment your code!!! No exceptions // comments start with ‘//’ You can write anything in a comm e nt {} are not () are not [] Commands need to be closed with ‘;’ A nalog (wave) vs digital (squared wave) Analog inputs, analog inputs vary from 0-1023 E.g. analogRead(potPin); //analog reads the potentiometer position D igital inputs/outputs has only two states D igital inputs/outputs: 0-1,LOW-HIGH digitalRead(buttonPin); //reads the button state digitalWrite(ledPin, HIGH); //turns the LED on D igital PMW outputs; 0-255 analogWrite(ledPin, 200); //turns the LED on a specific brightness General order of code //constant integers (whole numbers) const int name = x, //this creates an integer called ‘name’ with a constant value of ‘x’ ...