Author Topic: Arduino Tutorial #3 - Functions, return values and variables  (Read 9624 times)

MJLorton

  • Administrator
  • Hero Member
  • *****
  • Posts: 817
Arduino Tutorial #3 - Functions, return values and variables
« on: October 18, 2012, 01:38:14 AM »

This is the tutorial: http://www.youtube.com/watch?v=kV7FKL9FtwM

Here is the sample code / sketch I use in the tutorial:

/*
  Tutorial to demonstrate functions by Martin Lorton - http://www.MJLorton.com
  Solar Power and Electronic Measurement Equipment  -  http://www.youtube.com/user/mjlorton
*/

int AnsOne=0;

void setup() {
 Serial.begin(9600); // Setup serial port for terminal
 Serial.println("Hello YouTubers!");
 Serial.println("Let's do Math!");
 Addition (233,437);
 Serial.println(ValChk (AnsOne));
 Serial.println(Multiply (10));
 Serial.println("All Done!");
}
void loop() {};

void Addition (int ValOne, int ValTwo) {
  AnsOne=ValOne+ValTwo;
  Serial.print(ValOne);
  Serial.print("+");
  Serial.print(ValTwo);
  Serial.print("=");
  Serial.println(AnsOne);}
 
int ValChk (int ValAns){
  if (ValAns > 2000)
  return 1;
  else return 0;}

int Multiply (int ValFactor){
  int MultiAns=AnsOne*ValFactor;
  return MultiAns;}
« Last Edit: October 18, 2012, 02:47:25 AM by MJLorton »
Play, discover, learn and enjoy! (and don't be scared to make mistakes along the way!)