<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Veja6203</id>
	<title>Medien Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Veja6203"/>
	<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/Special:Contributions/Veja6203"/>
	<updated>2026-05-16T15:31:00Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.6</generator>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Actors,_Traces,_Collectives/SS17/Tracking&amp;diff=91838</id>
		<title>GMU:Actors, Traces, Collectives/SS17/Tracking</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Actors,_Traces,_Collectives/SS17/Tracking&amp;diff=91838"/>
		<updated>2017-06-24T14:33:57Z</updated>

		<summary type="html">&lt;p&gt;Veja6203: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;javaScript&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
import processing.video.*;&lt;br /&gt;
Capture video;&lt;br /&gt;
int x, y;&lt;br /&gt;
Mover [] mover = new Mover [20];&lt;br /&gt;
&lt;br /&gt;
void setup() {&lt;br /&gt;
&lt;br /&gt;
  size(640, 480);&lt;br /&gt;
  video = new Capture(this, width, height);&lt;br /&gt;
  video.start();&lt;br /&gt;
  for (int i = 0; i &amp;lt; mover.length; i++) {&lt;br /&gt;
    mover [i]=new Mover ();&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void draw() {&lt;br /&gt;
  if (video.available()) {&lt;br /&gt;
    video.read();&lt;br /&gt;
    image(video, 0, 0, width, height);&lt;br /&gt;
    int brightestX = 0; // X-coordinate of the brightest video pixel&lt;br /&gt;
    int brightestY = 0; // Y-coordinate of the brightest video pixel&lt;br /&gt;
    float brightestValue = 0; // Brightness of the brightest video pixel&lt;br /&gt;
    video.loadPixels();&lt;br /&gt;
    int index = 0;&lt;br /&gt;
    for (int y = 0; y &amp;lt; video.height; y++) {&lt;br /&gt;
      for (int x = 0; x &amp;lt; video.width; x++) {&lt;br /&gt;
        int pixelValue = video.pixels[index];&lt;br /&gt;
        float pixelBrightness = brightness(pixelValue);&lt;br /&gt;
        if (pixelBrightness &amp;gt; brightestValue) {&lt;br /&gt;
          brightestValue = pixelBrightness;&lt;br /&gt;
          brightestY = y;&lt;br /&gt;
          brightestX = x;&lt;br /&gt;
        }&lt;br /&gt;
        index++;&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    for (int j = 0; j &amp;lt; mover.length; j++) {&lt;br /&gt;
      // Update the position&lt;br /&gt;
      mover[j].update(brightestX, brightestY);&lt;br /&gt;
      // Display the Mover&lt;br /&gt;
      mover[j].display();&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// The Nature of Code&lt;br /&gt;
// Daniel Shiffman&lt;br /&gt;
// http://natureofcode.com&lt;br /&gt;
&lt;br /&gt;
class Mover {&lt;br /&gt;
&lt;br /&gt;
  // The Mover tracks position, velocity, and acceleration &lt;br /&gt;
  PVector position;&lt;br /&gt;
  PVector velocity;&lt;br /&gt;
  PVector dir;&lt;br /&gt;
  // The Mover&#039;s maximum speed&lt;br /&gt;
  float topspeed;&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
  Mover() {&lt;br /&gt;
    // Start in the center&lt;br /&gt;
    position = new PVector(random(width),random(height));&lt;br /&gt;
    velocity = new PVector(0,0);&lt;br /&gt;
    topspeed = 5;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  void update(float x, float y) {&lt;br /&gt;
    &lt;br /&gt;
    // Compute a vector that points from position to mouse&lt;br /&gt;
    PVector mouse = new PVector(x,y);&lt;br /&gt;
    PVector dir = PVector.sub(mouse,position);&lt;br /&gt;
    &lt;br /&gt;
    // Set magnitude of acceleration&lt;br /&gt;
    dir.setMag(0.3);&lt;br /&gt;
    &lt;br /&gt;
    // Velocity changes according to acceleration&lt;br /&gt;
    velocity.add(dir);&lt;br /&gt;
    &lt;br /&gt;
    // Limit the velocity by topspeed&lt;br /&gt;
    velocity.limit(topspeed);&lt;br /&gt;
    // position changes by velocity&lt;br /&gt;
    position.add(velocity);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  void display() {&lt;br /&gt;
    stroke(0);&lt;br /&gt;
    strokeWeight(2);&lt;br /&gt;
    //fill(127);&lt;br /&gt;
    //ellipse(position.x,position.y,48,48);&lt;br /&gt;
    line (position.x,position.y, position.x+velocity.x,position.y+velocity.y);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Veja6203</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Actors,_Traces,_Collectives/SS17/Tracking&amp;diff=91837</id>
		<title>GMU:Actors, Traces, Collectives/SS17/Tracking</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Actors,_Traces,_Collectives/SS17/Tracking&amp;diff=91837"/>
		<updated>2017-06-24T14:28:33Z</updated>

		<summary type="html">&lt;p&gt;Veja6203: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;javaScript&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
import processing.video.*;&lt;br /&gt;
Capture video;&lt;br /&gt;
int x, y;&lt;br /&gt;
Mover [] mover = new Mover [20];&lt;br /&gt;
&lt;br /&gt;
void setup() {&lt;br /&gt;
&lt;br /&gt;
  size(640, 480);&lt;br /&gt;
  video = new Capture(this, width, height);&lt;br /&gt;
  video.start();&lt;br /&gt;
  for (int i = 0; i &amp;lt; mover.length; i++) {&lt;br /&gt;
    mover [i]=new Mover ();&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void draw() {&lt;br /&gt;
  if (video.available()) {&lt;br /&gt;
    video.read();&lt;br /&gt;
    image(video, 0, 0, width, height);&lt;br /&gt;
    int brightestX = 0; // X-coordinate of the brightest video pixel&lt;br /&gt;
    int brightestY = 0; // Y-coordinate of the brightest video pixel&lt;br /&gt;
    float brightestValue = 0; // Brightness of the brightest video pixel&lt;br /&gt;
    video.loadPixels();&lt;br /&gt;
    int index = 0;&lt;br /&gt;
    for (int y = 0; y &amp;lt; video.height; y++) {&lt;br /&gt;
      for (int x = 0; x &amp;lt; video.width; x++) {&lt;br /&gt;
        int pixelValue = video.pixels[index];&lt;br /&gt;
        float pixelBrightness = brightness(pixelValue);&lt;br /&gt;
        if (pixelBrightness &amp;gt; brightestValue) {&lt;br /&gt;
          brightestValue = pixelBrightness;&lt;br /&gt;
          brightestY = y;&lt;br /&gt;
          brightestX = x;&lt;br /&gt;
        }&lt;br /&gt;
        index++;&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    for (int j = 0; j &amp;lt; mover.length; j++) {&lt;br /&gt;
      // Update the position&lt;br /&gt;
      mover[j].update(brightestX, brightestY);&lt;br /&gt;
      // Display the Mover&lt;br /&gt;
      mover[j].display();&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// The Nature of Code&lt;br /&gt;
// Daniel Shiffman&lt;br /&gt;
// http://natureofcode.com&lt;br /&gt;
&lt;br /&gt;
class Mover {&lt;br /&gt;
&lt;br /&gt;
  // The Mover tracks position, velocity, and acceleration &lt;br /&gt;
  PVector position;&lt;br /&gt;
  PVector velocity;&lt;br /&gt;
  PVector dir;&lt;br /&gt;
  // The Mover&#039;s maximum speed&lt;br /&gt;
  float topspeed;&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
  Mover() {&lt;br /&gt;
    // Start in the center&lt;br /&gt;
    position = new PVector(width/2,height/2);&lt;br /&gt;
    velocity = new PVector(0,0);&lt;br /&gt;
    topspeed = 5;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  void update(float x, float y) {&lt;br /&gt;
    &lt;br /&gt;
    // Compute a vector that points from position to mouse&lt;br /&gt;
    PVector mouse = new PVector(x,y);&lt;br /&gt;
    PVector dir = PVector.sub(mouse,position);&lt;br /&gt;
    &lt;br /&gt;
    // Set magnitude of acceleration&lt;br /&gt;
    dir.setMag(0.3);&lt;br /&gt;
    &lt;br /&gt;
    // Velocity changes according to acceleration&lt;br /&gt;
    velocity.add(dir);&lt;br /&gt;
    &lt;br /&gt;
    // Limit the velocity by topspeed&lt;br /&gt;
    velocity.limit(topspeed);&lt;br /&gt;
    // position changes by velocity&lt;br /&gt;
    position.add(velocity);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  void display() {&lt;br /&gt;
    stroke(0);&lt;br /&gt;
    strokeWeight(2);&lt;br /&gt;
    //fill(127);&lt;br /&gt;
    //ellipse(position.x,position.y,48,48);&lt;br /&gt;
    line (position.x,position.y, position.x+velocity.x,position.y+velocity.y);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Veja6203</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Actors,_Traces,_Collectives/SS17/Schachbrettmuster_Array&amp;diff=91776</id>
		<title>GMU:Actors, Traces, Collectives/SS17/Schachbrettmuster Array</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Actors,_Traces,_Collectives/SS17/Schachbrettmuster_Array&amp;diff=91776"/>
		<updated>2017-06-10T12:59:03Z</updated>

		<summary type="html">&lt;p&gt;Veja6203: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;javaScript&amp;quot;&amp;gt;&lt;br /&gt;
int  [][] rectPos;&lt;br /&gt;
&lt;br /&gt;
void setup () {&lt;br /&gt;
  size (800, 800);&lt;br /&gt;
  noLoop();&lt;br /&gt;
&lt;br /&gt;
  rectPos = new int [width/20][height/20];&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void draw() {&lt;br /&gt;
&lt;br /&gt;
  for (int j = 0; j &amp;lt; height /20; j ++) {&lt;br /&gt;
    for (int i =0; i &amp;lt; width/20; i ++) {&lt;br /&gt;
&lt;br /&gt;
      rectPos [i][j] = rectPos [i][j] + 20*i;&lt;br /&gt;
      &lt;br /&gt;
      if (i%2==0&amp;amp;&amp;amp;j%2==0) {&lt;br /&gt;
        fill(0);&lt;br /&gt;
      }else if(i%2!=0&amp;amp;&amp;amp;j%2!=0){&lt;br /&gt;
        fill(0);&lt;br /&gt;
      }else{&lt;br /&gt;
      fill (255);&lt;br /&gt;
      }&lt;br /&gt;
       rect (i*20, j*20, 20, 20 );&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Veja6203</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Actors,_Traces,_Collectives/SS17/Schachbrettmuster_Array&amp;diff=91775</id>
		<title>GMU:Actors, Traces, Collectives/SS17/Schachbrettmuster Array</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Actors,_Traces,_Collectives/SS17/Schachbrettmuster_Array&amp;diff=91775"/>
		<updated>2017-06-10T12:58:30Z</updated>

		<summary type="html">&lt;p&gt;Veja6203: Created page with &amp;quot;&amp;lt;syntaxhighlight lang=javaScript&amp;gt; int  [][] rectPos;  void setup () {   size (800, 800);   noLoop();    rectPos = new int [width/20][height/20]; }  void draw() {    for (int j...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;syntaxhighlight lang=javaScript&amp;gt;&lt;br /&gt;
int  [][] rectPos;&lt;br /&gt;
&lt;br /&gt;
void setup () {&lt;br /&gt;
  size (800, 800);&lt;br /&gt;
  noLoop();&lt;br /&gt;
&lt;br /&gt;
  rectPos = new int [width/20][height/20];&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void draw() {&lt;br /&gt;
&lt;br /&gt;
  for (int j = 0; j &amp;lt; height /20; j ++) {&lt;br /&gt;
    for (int i =0; i &amp;lt; width/20; i ++) {&lt;br /&gt;
&lt;br /&gt;
      rectPos [i][j] = rectPos [i][j] + 20*i;&lt;br /&gt;
      &lt;br /&gt;
      if (i%2==0&amp;amp;&amp;amp;j%2==0) {&lt;br /&gt;
        fill(0);&lt;br /&gt;
      }else if(i%2!=0&amp;amp;&amp;amp;j%2!=0){&lt;br /&gt;
        fill(0);&lt;br /&gt;
      }else{&lt;br /&gt;
      fill (255);&lt;br /&gt;
      }&lt;br /&gt;
       rect (i*20, j*20, 20, 20 );&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight lang=javaScript&amp;gt;&lt;/div&gt;</summary>
		<author><name>Veja6203</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Actors,_Traces,_Collectives/SS17&amp;diff=91774</id>
		<title>GMU:Actors, Traces, Collectives/SS17</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Actors,_Traces,_Collectives/SS17&amp;diff=91774"/>
		<updated>2017-06-10T12:57:23Z</updated>

		<summary type="html">&lt;p&gt;Veja6203: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Einführung ins Programmieren anhand von graphischen Beispielen&lt;br /&gt;
&lt;br /&gt;
[[:Category:Werkmodul|Werkmodul]]&amp;lt;br /&amp;gt;&lt;br /&gt;
&#039;&#039;Lehrender:&#039;&#039; [[Max Neupert]]&amp;lt;br /&amp;gt;&lt;br /&gt;
&#039;&#039;Punkte:&#039;&#039; 6 [[ECTS]], 4 [[SWS]]&amp;lt;br /&amp;gt;&lt;br /&gt;
&#039;&#039;Termine:&#039;&#039; 2017-06 jeweils Fr-So 9.-11., 23.-25. von 10 bis 18:30&amp;lt;br /&amp;gt;&lt;br /&gt;
&#039;&#039;Ort:&#039;&#039; [[Marienstraße 7b]], Seminarraum 204&amp;lt;br /&amp;gt;&lt;br /&gt;
&#039;&#039;Erstes Treffen:&#039;&#039; 2017-06-09&amp;lt;br /&amp;gt;&lt;br /&gt;
[https://www.uni-weimar.de/qisserver/rds?state=verpublish&amp;amp;status=init&amp;amp;vmfile=no&amp;amp;publishid=34713&amp;amp;moduleCall=webInfo&amp;amp;publishConfFile=webInfo&amp;amp;publishSubDir=veranstaltung Im VLV]&lt;br /&gt;
&lt;br /&gt;
==Kursbeschreibung==&lt;br /&gt;
Anhand von aufeinander aufbauenden praktischen Übungen werden Grundkonzepte des Programmierens eingeführt.&lt;br /&gt;
&lt;br /&gt;
Die Übungsergebnisse sind überwiegend grafischer Natur und führen von einfachen Bewegungsspuren über L-Systeme und einer klassischen Schwarmsimulation (Craig Reynold&#039;s Boids) zur Live-Verarbeitung von Kameradaten.&lt;br /&gt;
&lt;br /&gt;
Die Veranstaltung wird Java (Processing) oder JavaScript (P5.js) verwenden.&lt;br /&gt;
Kurssprache ist deutsch.&lt;br /&gt;
Die Veranstaltung richtet sich primär an ProgrammieranfängerInnen&lt;br /&gt;
&lt;br /&gt;
Inhalte sind u.a.:&lt;br /&gt;
&lt;br /&gt;
* [[Punkt]]&lt;br /&gt;
* Variablen&lt;br /&gt;
* Kontrollstrukturen (If/Then/Else, Schleifen)&lt;br /&gt;
** [[/if Bedingung/]] und Abfrage ob gerade oder ungerade (Modulo)&lt;br /&gt;
** Übung: [[/Kariert/]]&lt;br /&gt;
** Übung: [[/Schachbrettmuster/]] [[/Schachbrettmuster_Array/]]&lt;br /&gt;
* [[/Funktionen/]]&lt;br /&gt;
* [[/Zufall/]] + Vektorgrafik-Export&lt;br /&gt;
* Grundlagen Objektorientierung&lt;br /&gt;
* Grundlagen Rekursion&lt;br /&gt;
* Grundlagen Lineare Algebra für Grafikprogrammierung&lt;br /&gt;
* Einfachste Algorithmen (Bubblesort)&lt;br /&gt;
* Tracking von Bewegungen mit Background-Substraction&lt;br /&gt;
&lt;br /&gt;
==Teilnehmer==&lt;br /&gt;
===Bestätigt===&lt;br /&gt;
# Paul Hermann&lt;br /&gt;
# Benjamin Griesch&lt;br /&gt;
# Christian Doeller&lt;br /&gt;
# Corinna Thamm&lt;br /&gt;
# Maria Schween&lt;br /&gt;
# Denis Polec&lt;br /&gt;
# Grit Lieder&lt;br /&gt;
# Julius Baars&lt;br /&gt;
&lt;br /&gt;
==Ablauf==&lt;br /&gt;
Wir folgen grob Daniel Shiffmans Buch [http://natureofcode.com/book/introduction/ The Nature of Code] und dem Buch [http://www.generative-gestaltung.de/code Generative Gestaltung]&lt;br /&gt;
&lt;br /&gt;
==Links==&lt;br /&gt;
[[Processing/Links]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Werkmodul]]&lt;br /&gt;
[[Category:SS17]]&lt;br /&gt;
[[Category:Max Neupert]]&lt;br /&gt;
[[Category:Processing]]&lt;/div&gt;</summary>
		<author><name>Veja6203</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Actors,_Traces,_Collectives/SS17&amp;diff=91065</id>
		<title>GMU:Actors, Traces, Collectives/SS17</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Actors,_Traces,_Collectives/SS17&amp;diff=91065"/>
		<updated>2017-05-01T19:49:16Z</updated>

		<summary type="html">&lt;p&gt;Veja6203: /* Bestätigt */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Einführung ins Programmieren anhand von graphischen Beispielen&lt;br /&gt;
&lt;br /&gt;
[[:Category:Werkmodul|Werkmodul]]&amp;lt;br /&amp;gt;&lt;br /&gt;
&#039;&#039;Lehrender:&#039;&#039; [[Max Neupert]]&amp;lt;br /&amp;gt;&lt;br /&gt;
&#039;&#039;Punkte:&#039;&#039; 6 [[ECTS]], 4 [[SWS]]&amp;lt;br /&amp;gt;&lt;br /&gt;
&#039;&#039;Termine:&#039;&#039; 2017-06 jeweils Fr-So 9.-11., 23.-25. von 10 bis 18:30&amp;lt;br /&amp;gt;&lt;br /&gt;
&#039;&#039;Ort:&#039;&#039; [[Marienstraße 7b]], Seminarraum 204&amp;lt;br /&amp;gt;&lt;br /&gt;
&#039;&#039;Erstes Treffen:&#039;&#039; 2017-06-09&amp;lt;br /&amp;gt;&lt;br /&gt;
[https://www.uni-weimar.de/qisserver/rds?state=verpublish&amp;amp;status=init&amp;amp;vmfile=no&amp;amp;publishid=34713&amp;amp;moduleCall=webInfo&amp;amp;publishConfFile=webInfo&amp;amp;publishSubDir=veranstaltung Im VLV]&lt;br /&gt;
&lt;br /&gt;
==Kursbeschreibung==&lt;br /&gt;
Anhand von aufeinader aufbauenden praktischen Übungen werden Grundkonzepte des Programmierens eingeführt.&lt;br /&gt;
&lt;br /&gt;
Die Übungsergebnisse sind überwiegend grafischer Natur und führen von einfachen Bewegungsspuren über L-Systeme und einer klassischen Schwarmsimulation (Craig Reynold&#039;s Boids) zur Live-Verarbeitung von Kameradaten.&lt;br /&gt;
&lt;br /&gt;
Die Veranstaltung wird entweder Java (Processing) oder Javascript (P5.js) verwenden.&lt;br /&gt;
Kurssprache ist deutsch.&lt;br /&gt;
Die Veranstaltung richtet sich primär an ProgrammieranfängerInnen&lt;br /&gt;
&lt;br /&gt;
Inhalte sind u.a.:&lt;br /&gt;
&lt;br /&gt;
* Variablen&lt;br /&gt;
* Kontrollstrukturen (If/Then/Else, Schleifen)&lt;br /&gt;
* Funktionen&lt;br /&gt;
* Grundlagen Objektorientierung&lt;br /&gt;
* Grundlagen Rekursion&lt;br /&gt;
* Grundlagen Lineare Algebra für Grafikprogrammierung&lt;br /&gt;
* Einfachste Algorithmen (Bubblesort)&lt;br /&gt;
* Tracking von Bewegungen mit Background-Substraction&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Teilnehmer==&lt;br /&gt;
===Bestätigt===&lt;br /&gt;
# Paul Hermann&lt;br /&gt;
# Benjamin Griesch&lt;br /&gt;
# Christian Doeller&lt;br /&gt;
#&lt;br /&gt;
#&lt;br /&gt;
#&lt;br /&gt;
#&lt;br /&gt;
#&lt;br /&gt;
#&lt;br /&gt;
#&lt;br /&gt;
#&lt;br /&gt;
#&lt;br /&gt;
#&lt;br /&gt;
#&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
===Anmeldungen===&lt;br /&gt;
* Tommy Neuwirth&lt;br /&gt;
* Thu-Trang Da&lt;br /&gt;
* Corinna Thamm&lt;br /&gt;
* Denis Polec&lt;br /&gt;
* Julius Baars&lt;br /&gt;
* Paul Hermann&lt;br /&gt;
* Grit Lieder&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Werkmodul]]&lt;br /&gt;
[[Category:SS17]]&lt;br /&gt;
[[Category:Max Neupert]]&lt;br /&gt;
[[Category:Processing]]&lt;/div&gt;</summary>
		<author><name>Veja6203</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Actors,_Traces,_Collectives/SS17&amp;diff=91064</id>
		<title>GMU:Actors, Traces, Collectives/SS17</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Actors,_Traces,_Collectives/SS17&amp;diff=91064"/>
		<updated>2017-05-01T19:48:57Z</updated>

		<summary type="html">&lt;p&gt;Veja6203: /* Anmeldungen */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Einführung ins Programmieren anhand von graphischen Beispielen&lt;br /&gt;
&lt;br /&gt;
[[:Category:Werkmodul|Werkmodul]]&amp;lt;br /&amp;gt;&lt;br /&gt;
&#039;&#039;Lehrender:&#039;&#039; [[Max Neupert]]&amp;lt;br /&amp;gt;&lt;br /&gt;
&#039;&#039;Punkte:&#039;&#039; 6 [[ECTS]], 4 [[SWS]]&amp;lt;br /&amp;gt;&lt;br /&gt;
&#039;&#039;Termine:&#039;&#039; 2017-06 jeweils Fr-So 9.-11., 23.-25. von 10 bis 18:30&amp;lt;br /&amp;gt;&lt;br /&gt;
&#039;&#039;Ort:&#039;&#039; [[Marienstraße 7b]], Seminarraum 204&amp;lt;br /&amp;gt;&lt;br /&gt;
&#039;&#039;Erstes Treffen:&#039;&#039; 2017-06-09&amp;lt;br /&amp;gt;&lt;br /&gt;
[https://www.uni-weimar.de/qisserver/rds?state=verpublish&amp;amp;status=init&amp;amp;vmfile=no&amp;amp;publishid=34713&amp;amp;moduleCall=webInfo&amp;amp;publishConfFile=webInfo&amp;amp;publishSubDir=veranstaltung Im VLV]&lt;br /&gt;
&lt;br /&gt;
==Kursbeschreibung==&lt;br /&gt;
Anhand von aufeinader aufbauenden praktischen Übungen werden Grundkonzepte des Programmierens eingeführt.&lt;br /&gt;
&lt;br /&gt;
Die Übungsergebnisse sind überwiegend grafischer Natur und führen von einfachen Bewegungsspuren über L-Systeme und einer klassischen Schwarmsimulation (Craig Reynold&#039;s Boids) zur Live-Verarbeitung von Kameradaten.&lt;br /&gt;
&lt;br /&gt;
Die Veranstaltung wird entweder Java (Processing) oder Javascript (P5.js) verwenden.&lt;br /&gt;
Kurssprache ist deutsch.&lt;br /&gt;
Die Veranstaltung richtet sich primär an ProgrammieranfängerInnen&lt;br /&gt;
&lt;br /&gt;
Inhalte sind u.a.:&lt;br /&gt;
&lt;br /&gt;
* Variablen&lt;br /&gt;
* Kontrollstrukturen (If/Then/Else, Schleifen)&lt;br /&gt;
* Funktionen&lt;br /&gt;
* Grundlagen Objektorientierung&lt;br /&gt;
* Grundlagen Rekursion&lt;br /&gt;
* Grundlagen Lineare Algebra für Grafikprogrammierung&lt;br /&gt;
* Einfachste Algorithmen (Bubblesort)&lt;br /&gt;
* Tracking von Bewegungen mit Background-Substraction&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Teilnehmer==&lt;br /&gt;
===Bestätigt===&lt;br /&gt;
# Paul Hermann&lt;br /&gt;
# Benjamin Griesch&lt;br /&gt;
#&lt;br /&gt;
#&lt;br /&gt;
#&lt;br /&gt;
#&lt;br /&gt;
#&lt;br /&gt;
#&lt;br /&gt;
#&lt;br /&gt;
#&lt;br /&gt;
#&lt;br /&gt;
#&lt;br /&gt;
#&lt;br /&gt;
#&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
===Anmeldungen===&lt;br /&gt;
* Tommy Neuwirth&lt;br /&gt;
* Thu-Trang Da&lt;br /&gt;
* Corinna Thamm&lt;br /&gt;
* Denis Polec&lt;br /&gt;
* Julius Baars&lt;br /&gt;
* Paul Hermann&lt;br /&gt;
* Grit Lieder&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Werkmodul]]&lt;br /&gt;
[[Category:SS17]]&lt;br /&gt;
[[Category:Max Neupert]]&lt;br /&gt;
[[Category:Processing]]&lt;/div&gt;</summary>
		<author><name>Veja6203</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:StateMachine&amp;diff=90156</id>
		<title>GMU:StateMachine</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:StateMachine&amp;diff=90156"/>
		<updated>2017-03-28T14:08:42Z</updated>

		<summary type="html">&lt;p&gt;Veja6203: /* Structure */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;How can we tell a machine how to react to different situations and stimuli ?&lt;br /&gt;
&lt;br /&gt;
== Introduction == &lt;br /&gt;
&lt;br /&gt;
The state machine is an important concept in theoretical Computer Science. &amp;lt;br&amp;gt;&lt;br /&gt;
The following article explains how this concept can be used to program and organize different actions of simple robots. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Apparently there are:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;different reactions (outputs)&#039;&#039;&#039;&lt;br /&gt;
—&amp;gt; a robot can for instance move forward and backward, it can turn right or left and it can stand still.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;different stimuli (inputs)&#039;&#039;&#039;&lt;br /&gt;
—&amp;gt; a robot can for instance sense an obstacle (a wall), a human, …&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;different situations (states)&#039;&#039;&#039;&lt;br /&gt;
—&amp;gt; a robot can for instance be looking for a power plug, it can be running away from an opponent or it can be in resting mode.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We can imagine that only one possible output (action) is not enough to react to a diversity of inputs (stimuli) -&amp;lt;br&amp;gt;&lt;br /&gt;
It might be a good idea to move towards the closest wall if we are looking for a power plug. At the same time this would be rather bad if we are being chased by a prosecutor. &amp;lt;br&amp;gt;&lt;br /&gt;
We can also imagine that a suitable program can easily get quite complex and messy. &amp;lt;br&amp;gt;&lt;br /&gt;
Furthermore there is a good chance that some important relations between situations and reactions get lost in the programming process.&lt;br /&gt;
&lt;br /&gt;
So how can we make the whole thing a bit clearer?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Structure==&lt;br /&gt;
&lt;br /&gt;
A good way to deal with the possible complexity of such a program is to draw a corresponding diagram.&lt;br /&gt;
&lt;br /&gt;
There is another useful concept in theoretical Computer Science that can help us doing that:&amp;lt;br&amp;gt;&lt;br /&gt;
It says that it is enough to conduct only one predefined action (output) in reaction to the current situation (state) and to then look at the input data in order to analyze and decide the next situation (and so forth..). &amp;lt;br&amp;gt;&lt;br /&gt;
This kind of action pattern ([https://en.wikipedia.org/wiki/Moore_machine Moore Machine]) can be used in order to disassemble, restructure and consequently simplify similar sequences of much higher complexity ([https://en.wikipedia.org/wiki/Mealy_machine Mealy Machine]).&lt;br /&gt;
&lt;br /&gt;
And how can we use this strategy for our diagram?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We simply need to write down and structure the following things:&lt;br /&gt;
&lt;br /&gt;
* every possible situation (state)&lt;br /&gt;
—&amp;gt; hungry, looking for food, eating, ..&lt;br /&gt;
&lt;br /&gt;
* the particular conditions in which the situation (state) is changed&lt;br /&gt;
—&amp;gt; if sleeping and getting hungry -&amp;gt; looking for food, if looking for food and food has been found -&amp;gt; eating, ..&lt;br /&gt;
&lt;br /&gt;
* a list that includes every situation (state) in connection to one specific action (output) that is carried out as soon as the corresponding state arrives&lt;br /&gt;
—&amp;gt; looking for food / move around, eating / stop, ..&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Example: developing the control mechanism of an autonomous vacuum cleaner==&lt;br /&gt;
&lt;br /&gt;
All of the above will become much clearer if we look at an practical example of an autonomous vacuum cleaner robot. &amp;lt;br&amp;gt;&lt;br /&gt;
Step by step we will think of everything the robot has to do, put it in the right order and draw an appropriate diagram.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1) Turned on&lt;br /&gt;
&lt;br /&gt;
The robot stands still and waits for further instructions.&amp;lt;br&amp;gt;&lt;br /&gt;
It is now in standby mode.&lt;br /&gt;
&lt;br /&gt;
[[File:diagramStateMachine1.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2) On / Off - button pushed&lt;br /&gt;
&lt;br /&gt;
The robot starts to clean the room.&amp;lt;br&amp;gt;&lt;br /&gt;
It moves forward and activates the air pump.&lt;br /&gt;
&lt;br /&gt;
[[File:diagramStateMachine2.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3) Approaching a wall&lt;br /&gt;
&lt;br /&gt;
The robot would bump into the next wall if it would only be able to move forward.&amp;lt;br&amp;gt;&lt;br /&gt;
It therefore needs a function that recognizes walls and makes the robot turn around.&lt;br /&gt;
&lt;br /&gt;
[[File:diagramStateMachine3.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4) Turning around&lt;br /&gt;
&lt;br /&gt;
So far the robot turns randomly in any direction.&amp;lt;br&amp;gt;&lt;br /&gt;
We have to define a parameter that tells the robot if it turned enough in order to continue cleaning. &amp;lt;br&amp;gt;&lt;br /&gt;
This parameter can be a time delay, a certain amount of wheel revolutions or the value of a (distance, ..) sensor.&lt;br /&gt;
&lt;br /&gt;
[[File:diagramStateMachine4.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5) Turned off&lt;br /&gt;
&lt;br /&gt;
The final missing part is the off-button.&lt;br /&gt;
&lt;br /&gt;
[[File:diagramStateMachine5.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Writing the Program==&lt;br /&gt;
&lt;br /&gt;
Translating our diagram into a functional program is a relatively simple task.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1:&#039;&#039;&#039; saving the current state into a variable&lt;br /&gt;
&lt;br /&gt;
First of all we need a variable that saves the current state. It represents our State Machines memory. &amp;lt;br&amp;gt;&lt;br /&gt;
The most suitable type for such a variable is in this case an &amp;quot;[https://en.wikipedia.org/wiki/Enumerated_type enum]&amp;quot;.&amp;lt;br&amp;gt;&lt;br /&gt;
This enum assigns different names to values:&lt;br /&gt;
&lt;br /&gt;
[[File:robot_enum.jpg]]&lt;br /&gt;
&lt;br /&gt;
Note (enum + Processing): the definition of an enum has to be saved in a separate file (tab) with an .java extension. &amp;lt;br&amp;gt;([http://stackoverflow.com/questions/13370090/enums-in-processing-2-0 more info] )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 2:&#039;&#039;&#039; choosing alternative actions&lt;br /&gt;
&lt;br /&gt;
Now we need something that executes different code depending on the current state.&amp;lt;br&amp;gt;&lt;br /&gt;
For this purpose we will have a closer look at the [https://www.arduino.cc/en/Reference/SwitchCase switch/case] statement. &amp;lt;br&amp;gt;&lt;br /&gt;
It operates similar to an if-condition whereas it can choose from more than two (if… else..) alternatives. &amp;lt;br&amp;gt;&lt;br /&gt;
It could for instance run over and over again in the main loop-function of our program:&lt;br /&gt;
&lt;br /&gt;
[[File:robot_Loop1.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3:&#039;&#039;&#039; defining the practical behavior of each state&lt;br /&gt;
&lt;br /&gt;
From now on it makes sense to use functions (aggregation of code) in order to keep a clean overview of our program.&amp;lt;br&amp;gt;&lt;br /&gt;
Each function includes the particular code that defines the behavior of a certain state. &amp;lt;br&amp;gt;&lt;br /&gt;
The internal structure of these functions is always the same:&lt;br /&gt;
&lt;br /&gt;
1) conduct actions that fit to the particular state. (turn motors on / off, start a timer, ..)&amp;lt;br&amp;gt;&lt;br /&gt;
2) read input data (sensors, timer, ..) that provides information about the next possible state&amp;lt;br&amp;gt;&lt;br /&gt;
3) decide the next state &lt;br /&gt;
&lt;br /&gt;
The third part can be done quite comfortably by giving back the new &amp;quot;state&amp;quot; - value in form of the functions &amp;quot;return&amp;quot; - value into the main loop. &lt;br /&gt;
&lt;br /&gt;
This is an example of how the &amp;quot;standby&amp;quot;-state could look like:&lt;br /&gt;
&lt;br /&gt;
[[File:robot_standbyfunc.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 4:&#039;&#039;&#039; assembling everything&lt;br /&gt;
&lt;br /&gt;
We can now call each particular function in the appropriate part of the switch/case statement.&amp;lt;br&amp;gt;&lt;br /&gt;
The functions return value is saved in the state variable for the next loop.&lt;br /&gt;
&lt;br /&gt;
[[File:robot_Loop2.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 5:&#039;&#039;&#039; extending the program&lt;br /&gt;
&lt;br /&gt;
This kind of program structure can easily be extended by additional states without disturbing the overall clarity.&amp;lt;br&amp;gt;&lt;br /&gt;
Therefore it makes sense to begin with a simple structure and to then add functions that are more complex.&lt;/div&gt;</summary>
		<author><name>Veja6203</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:StateMachine&amp;diff=90155</id>
		<title>GMU:StateMachine</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:StateMachine&amp;diff=90155"/>
		<updated>2017-03-28T14:08:15Z</updated>

		<summary type="html">&lt;p&gt;Veja6203: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;How can we tell a machine how to react to different situations and stimuli ?&lt;br /&gt;
&lt;br /&gt;
== Introduction == &lt;br /&gt;
&lt;br /&gt;
The state machine is an important concept in theoretical Computer Science. &amp;lt;br&amp;gt;&lt;br /&gt;
The following article explains how this concept can be used to program and organize different actions of simple robots. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Apparently there are:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;different reactions (outputs)&#039;&#039;&#039;&lt;br /&gt;
—&amp;gt; a robot can for instance move forward and backward, it can turn right or left and it can stand still.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;different stimuli (inputs)&#039;&#039;&#039;&lt;br /&gt;
—&amp;gt; a robot can for instance sense an obstacle (a wall), a human, …&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;different situations (states)&#039;&#039;&#039;&lt;br /&gt;
—&amp;gt; a robot can for instance be looking for a power plug, it can be running away from an opponent or it can be in resting mode.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We can imagine that only one possible output (action) is not enough to react to a diversity of inputs (stimuli) -&amp;lt;br&amp;gt;&lt;br /&gt;
It might be a good idea to move towards the closest wall if we are looking for a power plug. At the same time this would be rather bad if we are being chased by a prosecutor. &amp;lt;br&amp;gt;&lt;br /&gt;
We can also imagine that a suitable program can easily get quite complex and messy. &amp;lt;br&amp;gt;&lt;br /&gt;
Furthermore there is a good chance that some important relations between situations and reactions get lost in the programming process.&lt;br /&gt;
&lt;br /&gt;
So how can we make the whole thing a bit clearer?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Structure==&lt;br /&gt;
&lt;br /&gt;
A good way to deal with the possible complexity of such a program is to draw a corresponding diagram.&lt;br /&gt;
&lt;br /&gt;
There is another useful concept in theoretical Computer Science that can help us doing that:&amp;lt;br&amp;gt;&lt;br /&gt;
It says that it is enough to conduct only one predefined action (output) in reaction to the current situation (state) and to then look at the input data in order to analyze and decide the next situation (and so forth..). &amp;lt;br&amp;gt;&lt;br /&gt;
This kind of action pattern ([https://en.wikipedia.org/wiki/Moore_machine Moore Machine]) can be used in order to disassemble, restructure and consequently simplify similar sequences of much higher complexity ([https://en.wikipedia.org/wiki/Mealy_machine Mealy Machine]).&lt;br /&gt;
&lt;br /&gt;
And how can we use this strategy for our diagram?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We simply need to write down and structure the following things:&lt;br /&gt;
&lt;br /&gt;
* every possible situation (state)&lt;br /&gt;
—&amp;gt; hungry, looking for food, eating, ..&lt;br /&gt;
&lt;br /&gt;
* the particular conditions in which the situation (state) is changed&lt;br /&gt;
—&amp;gt; if sleeping and getting hungry -&amp;gt; looking for food, if looking for food and food has been found -&amp;gt; eating, ..&lt;br /&gt;
&lt;br /&gt;
- a list that includes every situation (state) in connection to one specific action (output) that is carried out as soon as the corresponding state arrives&lt;br /&gt;
—&amp;gt; looking for food / move around, eating / stop, ..&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Example: developing the control mechanism of an autonomous vacuum cleaner==&lt;br /&gt;
&lt;br /&gt;
All of the above will become much clearer if we look at an practical example of an autonomous vacuum cleaner robot. &amp;lt;br&amp;gt;&lt;br /&gt;
Step by step we will think of everything the robot has to do, put it in the right order and draw an appropriate diagram.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1) Turned on&lt;br /&gt;
&lt;br /&gt;
The robot stands still and waits for further instructions.&amp;lt;br&amp;gt;&lt;br /&gt;
It is now in standby mode.&lt;br /&gt;
&lt;br /&gt;
[[File:diagramStateMachine1.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2) On / Off - button pushed&lt;br /&gt;
&lt;br /&gt;
The robot starts to clean the room.&amp;lt;br&amp;gt;&lt;br /&gt;
It moves forward and activates the air pump.&lt;br /&gt;
&lt;br /&gt;
[[File:diagramStateMachine2.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3) Approaching a wall&lt;br /&gt;
&lt;br /&gt;
The robot would bump into the next wall if it would only be able to move forward.&amp;lt;br&amp;gt;&lt;br /&gt;
It therefore needs a function that recognizes walls and makes the robot turn around.&lt;br /&gt;
&lt;br /&gt;
[[File:diagramStateMachine3.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4) Turning around&lt;br /&gt;
&lt;br /&gt;
So far the robot turns randomly in any direction.&amp;lt;br&amp;gt;&lt;br /&gt;
We have to define a parameter that tells the robot if it turned enough in order to continue cleaning. &amp;lt;br&amp;gt;&lt;br /&gt;
This parameter can be a time delay, a certain amount of wheel revolutions or the value of a (distance, ..) sensor.&lt;br /&gt;
&lt;br /&gt;
[[File:diagramStateMachine4.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5) Turned off&lt;br /&gt;
&lt;br /&gt;
The final missing part is the off-button.&lt;br /&gt;
&lt;br /&gt;
[[File:diagramStateMachine5.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Writing the Program==&lt;br /&gt;
&lt;br /&gt;
Translating our diagram into a functional program is a relatively simple task.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1:&#039;&#039;&#039; saving the current state into a variable&lt;br /&gt;
&lt;br /&gt;
First of all we need a variable that saves the current state. It represents our State Machines memory. &amp;lt;br&amp;gt;&lt;br /&gt;
The most suitable type for such a variable is in this case an &amp;quot;[https://en.wikipedia.org/wiki/Enumerated_type enum]&amp;quot;.&amp;lt;br&amp;gt;&lt;br /&gt;
This enum assigns different names to values:&lt;br /&gt;
&lt;br /&gt;
[[File:robot_enum.jpg]]&lt;br /&gt;
&lt;br /&gt;
Note (enum + Processing): the definition of an enum has to be saved in a separate file (tab) with an .java extension. &amp;lt;br&amp;gt;([http://stackoverflow.com/questions/13370090/enums-in-processing-2-0 more info] )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 2:&#039;&#039;&#039; choosing alternative actions&lt;br /&gt;
&lt;br /&gt;
Now we need something that executes different code depending on the current state.&amp;lt;br&amp;gt;&lt;br /&gt;
For this purpose we will have a closer look at the [https://www.arduino.cc/en/Reference/SwitchCase switch/case] statement. &amp;lt;br&amp;gt;&lt;br /&gt;
It operates similar to an if-condition whereas it can choose from more than two (if… else..) alternatives. &amp;lt;br&amp;gt;&lt;br /&gt;
It could for instance run over and over again in the main loop-function of our program:&lt;br /&gt;
&lt;br /&gt;
[[File:robot_Loop1.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3:&#039;&#039;&#039; defining the practical behavior of each state&lt;br /&gt;
&lt;br /&gt;
From now on it makes sense to use functions (aggregation of code) in order to keep a clean overview of our program.&amp;lt;br&amp;gt;&lt;br /&gt;
Each function includes the particular code that defines the behavior of a certain state. &amp;lt;br&amp;gt;&lt;br /&gt;
The internal structure of these functions is always the same:&lt;br /&gt;
&lt;br /&gt;
1) conduct actions that fit to the particular state. (turn motors on / off, start a timer, ..)&amp;lt;br&amp;gt;&lt;br /&gt;
2) read input data (sensors, timer, ..) that provides information about the next possible state&amp;lt;br&amp;gt;&lt;br /&gt;
3) decide the next state &lt;br /&gt;
&lt;br /&gt;
The third part can be done quite comfortably by giving back the new &amp;quot;state&amp;quot; - value in form of the functions &amp;quot;return&amp;quot; - value into the main loop. &lt;br /&gt;
&lt;br /&gt;
This is an example of how the &amp;quot;standby&amp;quot;-state could look like:&lt;br /&gt;
&lt;br /&gt;
[[File:robot_standbyfunc.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 4:&#039;&#039;&#039; assembling everything&lt;br /&gt;
&lt;br /&gt;
We can now call each particular function in the appropriate part of the switch/case statement.&amp;lt;br&amp;gt;&lt;br /&gt;
The functions return value is saved in the state variable for the next loop.&lt;br /&gt;
&lt;br /&gt;
[[File:robot_Loop2.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 5:&#039;&#039;&#039; extending the program&lt;br /&gt;
&lt;br /&gt;
This kind of program structure can easily be extended by additional states without disturbing the overall clarity.&amp;lt;br&amp;gt;&lt;br /&gt;
Therefore it makes sense to begin with a simple structure and to then add functions that are more complex.&lt;/div&gt;</summary>
		<author><name>Veja6203</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:StateMachine&amp;diff=90154</id>
		<title>GMU:StateMachine</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:StateMachine&amp;diff=90154"/>
		<updated>2017-03-28T14:07:02Z</updated>

		<summary type="html">&lt;p&gt;Veja6203: /* Writing the Program */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;How can we tell a machine how to react to different situations and stimuli ?&lt;br /&gt;
&lt;br /&gt;
== Introduction == &lt;br /&gt;
&lt;br /&gt;
The state machine is an important concept in theoretical Computer Science. &amp;lt;br&amp;gt;&lt;br /&gt;
The following article explains how this concept can be used to program and organize different actions of simple robots. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Apparently there are:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;different reactions (outputs)&#039;&#039;&#039;&lt;br /&gt;
—&amp;gt; a robot can for instance move forward and backward, it can turn right or left and it can stand still.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;different stimuli (inputs)&#039;&#039;&#039;&lt;br /&gt;
—&amp;gt; a robot can for instance sense an obstacle (a wall), a human, …&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;different situations (states)&#039;&#039;&#039;&lt;br /&gt;
—&amp;gt; a robot can for instance be looking for a power plug, it can be running away from an opponent or it can be in resting mode.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We can imagine that only one possible output (action) is not enough to react to a diversity of inputs (stimuli) -&amp;lt;br&amp;gt;&lt;br /&gt;
It might be a good idea to move towards the closest wall if we are looking for a power plug. At the same time this would be rather bad if we are being chased by a prosecutor. &amp;lt;br&amp;gt;&lt;br /&gt;
We can also imagine that a suitable program can easily get quite complex and messy. &amp;lt;br&amp;gt;&lt;br /&gt;
Furthermore there is a good chance that some important relations between situations and reactions get lost in the programming process.&lt;br /&gt;
&lt;br /&gt;
So how can we make the whole thing a bit clearer?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Structure==&lt;br /&gt;
&lt;br /&gt;
A good way to deal with the possible complexity of such a program is to draw a corresponding diagram.&lt;br /&gt;
&lt;br /&gt;
There is another useful concept in theoretical Computer Science that can help us doing that:&amp;lt;br&amp;gt;&lt;br /&gt;
It says that it is enough to conduct only one predefined action (output) in reaction to the current situation (state) and to then look at the input data in order to analyze and decide the next situation (and so forth..). &amp;lt;br&amp;gt;&lt;br /&gt;
This kind of action pattern ([https://en.wikipedia.org/wiki/Moore_machine Moore Machine]) can be used in order to disassemble, restructure and consequently simplify similar sequences of much higher complexity ([https://en.wikipedia.org/wiki/Mealy_machine Mealy Machine]).&lt;br /&gt;
&lt;br /&gt;
And how can we use this strategy for our diagram?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We simply need to write down and structure the following things:&lt;br /&gt;
&lt;br /&gt;
* every possible situation (state)&lt;br /&gt;
—&amp;gt; hungry, looking for food, eating, ..&lt;br /&gt;
&lt;br /&gt;
* the particular conditions in which the situation (state) is changed&lt;br /&gt;
—&amp;gt; if sleeping and getting hungry -&amp;gt; looking for food, if looking for food and food has been found -&amp;gt; eating, ..&lt;br /&gt;
&lt;br /&gt;
- a list that includes every situation (state) in connection to one specific action (output) that is carried out as soon as the corresponding state arrives&lt;br /&gt;
—&amp;gt; looking for food / move around, eating / stop, ..&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Example: developing the control mechanism of an autonomous vacuum cleaner==&lt;br /&gt;
&lt;br /&gt;
All of the above will become much clearer if we look at an practical example of an autonomous vacuum cleaner robot. &amp;lt;br&amp;gt;&lt;br /&gt;
Step by step we will think of everything the robot has to do, put it in the right order and draw an appropriate diagram.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1) Turned on&lt;br /&gt;
&lt;br /&gt;
The robot stands still and waits for further instructions.&amp;lt;br&amp;gt;&lt;br /&gt;
It is now in standby mode.&lt;br /&gt;
&lt;br /&gt;
[[File:diagramStateMachine1.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2) On / Off - button pushed&lt;br /&gt;
&lt;br /&gt;
The robot starts to clean the room.&amp;lt;br&amp;gt;&lt;br /&gt;
It moves forward and activates the air pump.&lt;br /&gt;
&lt;br /&gt;
[[File:diagramStateMachine2.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3) Approaching a wall&lt;br /&gt;
&lt;br /&gt;
The robot would bump into the next wall if it would only be able to move forward.&amp;lt;br&amp;gt;&lt;br /&gt;
It therefore needs a function that recognizes walls and makes the robot turn around.&lt;br /&gt;
&lt;br /&gt;
[[File:diagramStateMachine3.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4) Turning around&lt;br /&gt;
&lt;br /&gt;
So far the robot turns randomly in any direction.&amp;lt;br&amp;gt;&lt;br /&gt;
We have to define a parameter that tells the robot if it turned enough in order to continue cleaning. &amp;lt;br&amp;gt;&lt;br /&gt;
This parameter can be a time delay, a certain amount of wheel revolutions or the value of a (distance, ..) sensor.&lt;br /&gt;
&lt;br /&gt;
[[File:diagramStateMachine4.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5) Turned off&lt;br /&gt;
&lt;br /&gt;
The final missing part is the off-button.&lt;br /&gt;
&lt;br /&gt;
[[File:diagramStateMachine5.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Writing the Program==&lt;br /&gt;
&lt;br /&gt;
Translating our diagram into a functional program is a relatively simple task.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1:&#039;&#039;&#039; saving the current state into a variable&lt;br /&gt;
&lt;br /&gt;
First of all we need a variable that saves the current state. It represents our State Machines memory. &amp;lt;br&amp;gt;&lt;br /&gt;
The most suitable type for such a variable is in this case an „[https://en.wikipedia.org/wiki/Enumerated_type enum]“.&amp;lt;br&amp;gt;&lt;br /&gt;
This enum assigns different names to values:&lt;br /&gt;
&lt;br /&gt;
[[File:robot_enum.jpg]]&lt;br /&gt;
&lt;br /&gt;
Note (enum + Processing): the definition of an enum has to be saved in a separate file (tab) with an .java extension. &amp;lt;br&amp;gt;([http://stackoverflow.com/questions/13370090/enums-in-processing-2-0 more info] )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 2:&#039;&#039;&#039; choosing alternative actions&lt;br /&gt;
&lt;br /&gt;
Now we need something that executes different code depending on the current state.&amp;lt;br&amp;gt;&lt;br /&gt;
For this purpose we will have a closer look at the [https://www.arduino.cc/en/Reference/SwitchCase switch/case] statement. &amp;lt;br&amp;gt;&lt;br /&gt;
It operates similar to an if-condition whereas it can choose from more than two (if… else..) alternatives. &amp;lt;br&amp;gt;&lt;br /&gt;
It could for instance run over and over again in the main loop-function of our program:&lt;br /&gt;
&lt;br /&gt;
[[File:robot_Loop1.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3:&#039;&#039;&#039; defining the practical behavior of each state&lt;br /&gt;
&lt;br /&gt;
From now on it makes sense to use functions (aggregation of code) in order to keep a clean overview of our program.&amp;lt;br&amp;gt;&lt;br /&gt;
Each function includes the particular code that defines the behavior of a certain state. &amp;lt;br&amp;gt;&lt;br /&gt;
The internal structure of these functions is always the same:&lt;br /&gt;
&lt;br /&gt;
1) conduct actions that fit to the particular state. (turn motors on / off, start a timer, ..)&amp;lt;br&amp;gt;&lt;br /&gt;
2) read input data (sensors, timer, ..) that provides information about the next possible state&amp;lt;br&amp;gt;&lt;br /&gt;
3) decide the next state &lt;br /&gt;
&lt;br /&gt;
The third part can be done quite comfortably by giving back the new „state“ - value in form of the functions „return“ - value into the main loop. &lt;br /&gt;
&lt;br /&gt;
This is an example of how the „standy“-state could look like:&lt;br /&gt;
&lt;br /&gt;
[[File:robot_standbyfunc.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 4:&#039;&#039;&#039; assembling everything&lt;br /&gt;
&lt;br /&gt;
We can now call each particular function in the appropriate part of the switch/case statement.&amp;lt;br&amp;gt;&lt;br /&gt;
The functions return value is saved in the state variable for the next loop.&lt;br /&gt;
&lt;br /&gt;
[[File:robot_Loop2.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 5:&#039;&#039;&#039; extending the program&lt;br /&gt;
&lt;br /&gt;
This kind of program structure can easily be extended by additional states without disturbing the overall clarity.&amp;lt;br&amp;gt;&lt;br /&gt;
Therefore it makes sense to begin with a simple structure and to then add functions that are more complex.&lt;/div&gt;</summary>
		<author><name>Veja6203</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:StateMachine&amp;diff=90153</id>
		<title>GMU:StateMachine</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:StateMachine&amp;diff=90153"/>
		<updated>2017-03-28T14:05:37Z</updated>

		<summary type="html">&lt;p&gt;Veja6203: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;How can we tell a machine how to react to different situations and stimuli ?&lt;br /&gt;
&lt;br /&gt;
== Introduction == &lt;br /&gt;
&lt;br /&gt;
The state machine is an important concept in theoretical Computer Science. &amp;lt;br&amp;gt;&lt;br /&gt;
The following article explains how this concept can be used to program and organize different actions of simple robots. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Apparently there are:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;different reactions (outputs)&#039;&#039;&#039;&lt;br /&gt;
—&amp;gt; a robot can for instance move forward and backward, it can turn right or left and it can stand still.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;different stimuli (inputs)&#039;&#039;&#039;&lt;br /&gt;
—&amp;gt; a robot can for instance sense an obstacle (a wall), a human, …&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;different situations (states)&#039;&#039;&#039;&lt;br /&gt;
—&amp;gt; a robot can for instance be looking for a power plug, it can be running away from an opponent or it can be in resting mode.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We can imagine that only one possible output (action) is not enough to react to a diversity of inputs (stimuli) -&amp;lt;br&amp;gt;&lt;br /&gt;
It might be a good idea to move towards the closest wall if we are looking for a power plug. At the same time this would be rather bad if we are being chased by a prosecutor. &amp;lt;br&amp;gt;&lt;br /&gt;
We can also imagine that a suitable program can easily get quite complex and messy. &amp;lt;br&amp;gt;&lt;br /&gt;
Furthermore there is a good chance that some important relations between situations and reactions get lost in the programming process.&lt;br /&gt;
&lt;br /&gt;
So how can we make the whole thing a bit clearer?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Structure==&lt;br /&gt;
&lt;br /&gt;
A good way to deal with the possible complexity of such a program is to draw a corresponding diagram.&lt;br /&gt;
&lt;br /&gt;
There is another useful concept in theoretical Computer Science that can help us doing that:&amp;lt;br&amp;gt;&lt;br /&gt;
It says that it is enough to conduct only one predefined action (output) in reaction to the current situation (state) and to then look at the input data in order to analyze and decide the next situation (and so forth..). &amp;lt;br&amp;gt;&lt;br /&gt;
This kind of action pattern ([https://en.wikipedia.org/wiki/Moore_machine Moore Machine]) can be used in order to disassemble, restructure and consequently simplify similar sequences of much higher complexity ([https://en.wikipedia.org/wiki/Mealy_machine Mealy Machine]).&lt;br /&gt;
&lt;br /&gt;
And how can we use this strategy for our diagram?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We simply need to write down and structure the following things:&lt;br /&gt;
&lt;br /&gt;
* every possible situation (state)&lt;br /&gt;
—&amp;gt; hungry, looking for food, eating, ..&lt;br /&gt;
&lt;br /&gt;
* the particular conditions in which the situation (state) is changed&lt;br /&gt;
—&amp;gt; if sleeping and getting hungry -&amp;gt; looking for food, if looking for food and food has been found -&amp;gt; eating, ..&lt;br /&gt;
&lt;br /&gt;
- a list that includes every situation (state) in connection to one specific action (output) that is carried out as soon as the corresponding state arrives&lt;br /&gt;
—&amp;gt; looking for food / move around, eating / stop, ..&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Example: developing the control mechanism of an autonomous vacuum cleaner==&lt;br /&gt;
&lt;br /&gt;
All of the above will become much clearer if we look at an practical example of an autonomous vacuum cleaner robot. &amp;lt;br&amp;gt;&lt;br /&gt;
Step by step we will think of everything the robot has to do, put it in the right order and draw an appropriate diagram.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1) Turned on&lt;br /&gt;
&lt;br /&gt;
The robot stands still and waits for further instructions.&amp;lt;br&amp;gt;&lt;br /&gt;
It is now in standby mode.&lt;br /&gt;
&lt;br /&gt;
[[File:diagramStateMachine1.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2) On / Off - button pushed&lt;br /&gt;
&lt;br /&gt;
The robot starts to clean the room.&amp;lt;br&amp;gt;&lt;br /&gt;
It moves forward and activates the air pump.&lt;br /&gt;
&lt;br /&gt;
[[File:diagramStateMachine2.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3) Approaching a wall&lt;br /&gt;
&lt;br /&gt;
The robot would bump into the next wall if it would only be able to move forward.&amp;lt;br&amp;gt;&lt;br /&gt;
It therefore needs a function that recognizes walls and makes the robot turn around.&lt;br /&gt;
&lt;br /&gt;
[[File:diagramStateMachine3.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
4) Turning around&lt;br /&gt;
&lt;br /&gt;
So far the robot turns randomly in any direction.&amp;lt;br&amp;gt;&lt;br /&gt;
We have to define a parameter that tells the robot if it turned enough in order to continue cleaning. &amp;lt;br&amp;gt;&lt;br /&gt;
This parameter can be a time delay, a certain amount of wheel revolutions or the value of a (distance, ..) sensor.&lt;br /&gt;
&lt;br /&gt;
[[File:diagramStateMachine4.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5) Turned off&lt;br /&gt;
&lt;br /&gt;
The final missing part is the off-button.&lt;br /&gt;
&lt;br /&gt;
[[File:diagramStateMachine5.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Writing the Program==&lt;br /&gt;
&lt;br /&gt;
Translating our diagram into a functional program is a relatively simple task.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 1:&#039;&#039;&#039; saving the current state into a variable&lt;br /&gt;
&lt;br /&gt;
First of all we need a variable that saves the current state. It represents our State Machines memory. &amp;lt;br&amp;gt;&lt;br /&gt;
The most suitable type for such a variable is in this case an „[https://en.wikipedia.org/wiki/Enumerated_type enum]“.&amp;lt;br&amp;gt;&lt;br /&gt;
This enum assigns different names to values:&lt;br /&gt;
&lt;br /&gt;
[[File:robot_enum.jpg]]&lt;br /&gt;
&lt;br /&gt;
Note (enum + Processing): the definition of an enum has to be saved in a separate file (tab) with an .java extension. &amp;lt;br&amp;gt;([http://stackoverflow.com/questions/13370090/enums-in-processing-2-0 more info] )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 2:&#039;&#039;&#039; choosing alternative actions&lt;br /&gt;
&lt;br /&gt;
Now we need something that executes different code depending on the current state.&amp;lt;br&amp;gt;&lt;br /&gt;
For this purpose we will have a closer look at the [https://www.arduino.cc/en/Reference/SwitchCase switch/case] statement. &amp;lt;br&amp;gt;&lt;br /&gt;
It operates similar to an if-condition whereas it can choose from more than two (if… else..) alternatives. &amp;lt;br&amp;gt;&lt;br /&gt;
It could for instance run over and over again in the main loop-function of our program:&lt;br /&gt;
&lt;br /&gt;
[[File:robot_Loop1.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 3:&#039;&#039;&#039; defining the practical behavior of each state&lt;br /&gt;
&lt;br /&gt;
From now on it makes sense to use functions (aggregation of code) in order to keep a clean overview of our program.&amp;lt;br&amp;gt;&lt;br /&gt;
Each function includes the particular code that defines the behavior of a certain state. &amp;lt;br&amp;gt;&lt;br /&gt;
The internal structure of these functions is always the same:&lt;br /&gt;
&lt;br /&gt;
1) conduct actions that fit to the particular state. (turn motors on / off, start a timer, ..)&lt;br /&gt;
2) read input data (sensors, timer, ..) that provides information about the next possible state&lt;br /&gt;
3) decide the next state &lt;br /&gt;
&lt;br /&gt;
The third part can be done quite comfortably by giving back the new „state“ - value in form of the functions „return“ - value into the main loop. &lt;br /&gt;
&lt;br /&gt;
This is an example of how the „standy“-state could look like:&lt;br /&gt;
&lt;br /&gt;
[[File:robot_standbyfunc.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 4:&#039;&#039;&#039; assembling everything&lt;br /&gt;
&lt;br /&gt;
We can now call each particular function in the appropriate part of the switch/case statement.&amp;lt;br&amp;gt;&lt;br /&gt;
The functions return value is saved in the state variable for the next loop.&lt;br /&gt;
&lt;br /&gt;
[[File:robot_Loop2.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Step 5:&#039;&#039;&#039; extending the program&lt;br /&gt;
&lt;br /&gt;
This kind of program structure can easily be extended by additional states without disturbing the overall clarity.&amp;lt;br&amp;gt;&lt;br /&gt;
Therefore it makes sense to begin with a simple structure and to then add functions that are more complex.&lt;/div&gt;</summary>
		<author><name>Veja6203</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90152</id>
		<title>GMU:Functions and Classes (Arduino)</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90152"/>
		<updated>2017-03-28T14:02:08Z</updated>

		<summary type="html">&lt;p&gt;Veja6203: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Motivation==&lt;br /&gt;
&lt;br /&gt;
Soon after starting to write the program for your robot you will encounter some typical problems:&lt;br /&gt;
&lt;br /&gt;
* clarity: the bigger the program gets the harder it is to keep the general overview&lt;br /&gt;
* decoupling: you only want to change a certain part of the program without influencing all the rest of it&lt;br /&gt;
* recyclability: there are several similar parts in your robot for which you would like to reuse particular sections of your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These problems reach back to the beginning of programming and their solution is an art and a science at the same time.&amp;lt;br&amp;gt;&lt;br /&gt;
It generally helps a lot to separate your program into single subunits that are relatively independent from each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example: Controlling Motors==&lt;br /&gt;
&lt;br /&gt;
The [http://arduino.cc/de/Reference/FunctionDeclaration function] is an enormous useful tool that can help you structuring your code. Functions allow you to sum up several operations under the same command. This command can be called again and again without knowing about or duplicating the included code. &lt;br /&gt;
&lt;br /&gt;
Here is an example for a function that sets the speed of a motor which is connected to an H-bridge:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD1.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now (and for every prospective motor movement) we only need to write one single line in order to for instance setting the left wheels speed:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD2.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This already saves us a lot of typing –&amp;lt;br&amp;gt;&lt;br /&gt;
But one thing still seems quite laborious: we have to know the exact pin numbers every time when we want to change the speed.&lt;br /&gt;
&lt;br /&gt;
Imagine a program in which similar function calls are distributed all over. &amp;lt;br&amp;gt;&lt;br /&gt;
In case of a hardware update you would have to find every single function call and change the parameters manually. &amp;lt;br&amp;gt;&lt;br /&gt;
This effort could surely be spent for more useful things..&lt;br /&gt;
&lt;br /&gt;
It would be ideal to find a way of calling a certain function that only offers the most useful parameters (like setting the speed) and which handles technical details (switching pins on and off) internally.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Possible Solution: Data and Code in One Package – &amp;quot;Classes&amp;quot; and &amp;quot;Objects&amp;quot;==&lt;br /&gt;
&lt;br /&gt;
C++ (and also Arduino) provides a specific feature that can solve our problem: Classes and Objects.&lt;br /&gt;
&lt;br /&gt;
A Class predefines common qualities of a group of Objects. &amp;lt;br&amp;gt;&lt;br /&gt;
It for instance determines that every motor has the possibility to exert a certain amount of throttle. &amp;lt;br&amp;gt;&lt;br /&gt;
The corresponding program could look like this:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD3.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now the computer knows that there is a class called &amp;quot;Motor&amp;quot;.&amp;lt;br&amp;gt;&lt;br /&gt;
This class (class) provides a function called &amp;quot;setThrottle&amp;quot; that is called as an argument by using a number (int) and that does not return anything (void).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Classes are Data Types===&lt;br /&gt;
&lt;br /&gt;
We can use our &amp;quot;Motor&amp;quot; - class the same way we are using other data - types (int, long, float).&amp;lt;br&amp;gt;&lt;br /&gt;
The following lines use that quality in order to implement two motors:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD4.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Calling inner functions of a class (Methods)===&lt;br /&gt;
&lt;br /&gt;
Imagine we want to drive the left motor with full throttle whereas the right motor should stop completely. &amp;lt;br&amp;gt;&lt;br /&gt;
This can be expressed as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD5.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A positive side effect: your program gains readability by picking distinct names for your Objects and Methods.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Classes can contain other variables that can only be accessed &amp;quot;internally&amp;quot;===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do the Objects &amp;quot;leftMotor&amp;quot; and &amp;quot;rightMotor&amp;quot; know which pins they want to switch on and off?&lt;br /&gt;
&lt;br /&gt;
Until now our &amp;quot;Motor&amp;quot; class is quite abstract since it does not contain this information. &amp;lt;br&amp;gt;&lt;br /&gt;
A class that should conduct practical actions needs further variables (concrete pin numbers) and lines of code that describe what to do exactly.&amp;lt;br&amp;gt;&lt;br /&gt;
We can simply include both things in the class definition:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD6.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do we include the pin numbers into the Object if they are not visible from the outside?&amp;lt;br&amp;gt;&lt;br /&gt;
We simply write a &amp;quot;setup&amp;quot; Function for the class:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD7.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==A Complete Example ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to construct a complete example we only have to include the &amp;quot;speed&amp;quot;-Function (see description above):&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD8.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Organizing Classes in Separate Files==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We can improve our program structure by putting classes in separate files:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;br&amp;gt;&lt;br /&gt;
Click on the arrow in the right corner in order to add a new file.&amp;lt;br&amp;gt;&lt;br /&gt;
Select &amp;quot;new Tab&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:NewTabARDU.jpg]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
2.&amp;lt;br&amp;gt;&lt;br /&gt;
Enter a filename at the bottom of the window. &amp;lt;br&amp;gt;&lt;br /&gt;
It must end with &amp;quot;.h&amp;quot; – In our case it could be &amp;quot;motorControl.h&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;br&amp;gt;&lt;br /&gt;
The first line of your code should be:&lt;br /&gt;
&lt;br /&gt;
&#039;#include „Arduino.h“&#039;&lt;br /&gt;
&lt;br /&gt;
This line &#039;links&#039; the file to the Arduino–specific features.&amp;lt;br&amp;gt;&lt;br /&gt;
Now we can include the code of our class.&lt;br /&gt;
&lt;br /&gt;
4.&amp;lt;br&amp;gt;&lt;br /&gt;
Go back to your main file.&amp;lt;br&amp;gt;&lt;br /&gt;
Now you have to &amp;quot;link&amp;quot; the new file to your main file in order to use the features of our class.&amp;lt;br&amp;gt;&lt;br /&gt;
Include the following line in the top of your main file&lt;br /&gt;
&lt;br /&gt;
&#039;#include &amp;quot;MotorControl.h“&#039;&lt;br /&gt;
&lt;br /&gt;
and write the rest of your program as usual.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==More Information==&lt;br /&gt;
&lt;br /&gt;
Classes can build up on each other (&amp;quot;inheritance&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
In the beginning we promised that it is possible to replace different motor drivers without changing the rest of the program.&amp;lt;br&amp;gt;&lt;br /&gt;
Classes can indeed include other Objects in the form of &amp;quot;[https://en.wikipedia.org/wiki/Member_variable member variables]&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
C++ allows class declarations and the code for included Functions to be be placed in different files. &amp;lt;br&amp;gt;&lt;br /&gt;
If you want to know more about that you can read this article about creating libraries in Arduino: &amp;lt;br&amp;gt;[http://arduino.cc/en/Hacking/LibraryTutorial http://arduino.cc/en/Hacking/LibraryTutorial ]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Veja6203</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90151</id>
		<title>GMU:Functions and Classes (Arduino)</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90151"/>
		<updated>2017-03-28T13:53:38Z</updated>

		<summary type="html">&lt;p&gt;Veja6203: /* More Information */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Motivation==&lt;br /&gt;
&lt;br /&gt;
Soon after starting to write the program for your robot you will encounter some typical problems:&lt;br /&gt;
&lt;br /&gt;
* clarity: the bigger the program gets the harder it is to keep the general overview&lt;br /&gt;
* decoupling: you only want to change a certain part of the program without influencing all the rest&lt;br /&gt;
* recyclability: there are several similar parts in your robot for which you would like to reuse particular sections of your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These problems reach back to the beginning of programming and their solution is an art and a science at the same time.&amp;lt;br&amp;gt;&lt;br /&gt;
It generally helps a lot to separate your program into single subunits that are relatively independent from each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example: Controlling Motors==&lt;br /&gt;
&lt;br /&gt;
The [http://arduino.cc/de/Reference/FunctionDeclaration function] is an enormous useful tool that can help you structuring your code. Functions allow you to sum up several operations under the same command. This command can be called again and again without knowing about or duplicating the included code. &lt;br /&gt;
&lt;br /&gt;
Here is an example for a function for setting the speed of a motor that is connected to an H-bridge:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD1.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now (and for every prospective motor movement) we only need to write one single line in order to for instance setting the left wheels speed:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD2.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This already saves us a lot of typing –&amp;lt;br&amp;gt;&lt;br /&gt;
But one thing still seems quite laborious: we have to know the exact pin numbers every time we want to change the speed.&lt;br /&gt;
&lt;br /&gt;
Imagine a program in which similar function calls are distributed all over. &amp;lt;br&amp;gt;&lt;br /&gt;
In case of a hardware update you would have to find every single function call and change the parameters manually. &amp;lt;br&amp;gt;&lt;br /&gt;
This effort could surely be spent for more useful things..&lt;br /&gt;
&lt;br /&gt;
It would be ideal to find a way of calling a certain function that only offers the most useful parameters (like setting the speed) and which handles technical details (switching pins on and off) internally.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Possible solution: Data and code in one package – „Classes“ and „Objects“==&lt;br /&gt;
&lt;br /&gt;
C++ (and also Arduino) provides a specific feature that can solve our problem: Classes and Objects&lt;br /&gt;
&lt;br /&gt;
A Class predefines common qualities of a group of Objects. &amp;lt;br&amp;gt;&lt;br /&gt;
It for instance determines that every motor has the possibility to exert a certain amount of throttle. &amp;lt;br&amp;gt;&lt;br /&gt;
The corresponding program could look like this:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD3.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now the computer knows that there is a class called „Motor“.&amp;lt;br&amp;gt;&lt;br /&gt;
This class (class) provides a function called „setThrottle“ that is called as an argument by using a number (int) and that does not return anything (void).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Classes are Data-types===&lt;br /&gt;
&lt;br /&gt;
We can use our „Motor“ - class the same way we are using other data - types (int, long, float).&amp;lt;br&amp;gt;&lt;br /&gt;
The following lines use that quality in order to implement two motors:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD4.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Calling inner functions of a class (Methods)===&lt;br /&gt;
&lt;br /&gt;
Imagine we want to drive the left motor with full throttle whereas the right motor should stop completely. &amp;lt;br&amp;gt;&lt;br /&gt;
This can be expressed as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD5.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A positive side effect: your program gains readability by picking distinct names for your Objects and Methods.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Classes can contain other variables that can only be accessed „internally“===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do the Objects „leftMotor“ and „rightMotor“ know which pins they want to switch on and off?&lt;br /&gt;
&lt;br /&gt;
Until now our „Motor“ class is quite abstract since it does not contain this information. &amp;lt;br&amp;gt;&lt;br /&gt;
A class that should conduct practical actions needs further variables (concrete pin numbers) and lines of code that describe what to do exactly.&amp;lt;br&amp;gt;&lt;br /&gt;
We can simply include both things in the class definition:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD6.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do we include the pin numbers into the Object if they are not visible from the outside?&amp;lt;br&amp;gt;&lt;br /&gt;
We simply write a „setup“ Function for the class:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD7.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==A complete example ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to construct a complete example we only have to include the „speed“-Function (see description above):&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD8.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Organizing classes in separate files==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We can improve our program structure by putting classes in separate files:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;br&amp;gt;&lt;br /&gt;
Click on the arrow in the right corner in order to add a new file.&amp;lt;br&amp;gt;&lt;br /&gt;
Select „new Tab“.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:NewTabARDU.jpg]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
2.&amp;lt;br&amp;gt;&lt;br /&gt;
Enter a filename at the bottom of the window. &amp;lt;br&amp;gt;&lt;br /&gt;
It must end with &#039;.h&#039; – In our case it could be &#039;motorControl.h&#039;.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;br&amp;gt;&lt;br /&gt;
The first line of your code should be:&lt;br /&gt;
&lt;br /&gt;
&#039;#include „Arduino.h“&#039;&lt;br /&gt;
&lt;br /&gt;
This line &#039;links&#039; the file to the Arduino–specific features.&amp;lt;br&amp;gt;&lt;br /&gt;
Now we can include the code of our class.&lt;br /&gt;
&lt;br /&gt;
4.&amp;lt;br&amp;gt;&lt;br /&gt;
Go back to your main file.&amp;lt;br&amp;gt;&lt;br /&gt;
Now you have to &#039;link&#039; the new file to your main file in order to use the features of our class.&amp;lt;br&amp;gt;&lt;br /&gt;
Include the following line in the top of your main file&lt;br /&gt;
&lt;br /&gt;
&#039;#include &amp;quot;MotorControl.h“&#039;&lt;br /&gt;
&lt;br /&gt;
and write the rest of your program as usual.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==More Information==&lt;br /&gt;
&lt;br /&gt;
Classes can build up on each other (&amp;quot;inheritance&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
In the beginning we promised that it is possible to replace different motor drivers without changing the rest of the program.&amp;lt;br&amp;gt;&lt;br /&gt;
Classes can indeed include other Objects in the form of „member variables“.&lt;br /&gt;
&lt;br /&gt;
C++ allows class declarations and the code for included Functions to be be placed in different files. &amp;lt;br&amp;gt;&lt;br /&gt;
If you want to know more about that you can read this article about creating libraries in Arduino: &amp;lt;br&amp;gt;[http://arduino.cc/en/Hacking/LibraryTutorial http://arduino.cc/en/Hacking/LibraryTutorial ]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Veja6203</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90150</id>
		<title>GMU:Functions and Classes (Arduino)</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90150"/>
		<updated>2017-03-28T13:53:01Z</updated>

		<summary type="html">&lt;p&gt;Veja6203: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Motivation==&lt;br /&gt;
&lt;br /&gt;
Soon after starting to write the program for your robot you will encounter some typical problems:&lt;br /&gt;
&lt;br /&gt;
* clarity: the bigger the program gets the harder it is to keep the general overview&lt;br /&gt;
* decoupling: you only want to change a certain part of the program without influencing all the rest&lt;br /&gt;
* recyclability: there are several similar parts in your robot for which you would like to reuse particular sections of your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These problems reach back to the beginning of programming and their solution is an art and a science at the same time.&amp;lt;br&amp;gt;&lt;br /&gt;
It generally helps a lot to separate your program into single subunits that are relatively independent from each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example: Controlling Motors==&lt;br /&gt;
&lt;br /&gt;
The [http://arduino.cc/de/Reference/FunctionDeclaration function] is an enormous useful tool that can help you structuring your code. Functions allow you to sum up several operations under the same command. This command can be called again and again without knowing about or duplicating the included code. &lt;br /&gt;
&lt;br /&gt;
Here is an example for a function for setting the speed of a motor that is connected to an H-bridge:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD1.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now (and for every prospective motor movement) we only need to write one single line in order to for instance setting the left wheels speed:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD2.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This already saves us a lot of typing –&amp;lt;br&amp;gt;&lt;br /&gt;
But one thing still seems quite laborious: we have to know the exact pin numbers every time we want to change the speed.&lt;br /&gt;
&lt;br /&gt;
Imagine a program in which similar function calls are distributed all over. &amp;lt;br&amp;gt;&lt;br /&gt;
In case of a hardware update you would have to find every single function call and change the parameters manually. &amp;lt;br&amp;gt;&lt;br /&gt;
This effort could surely be spent for more useful things..&lt;br /&gt;
&lt;br /&gt;
It would be ideal to find a way of calling a certain function that only offers the most useful parameters (like setting the speed) and which handles technical details (switching pins on and off) internally.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Possible solution: Data and code in one package – „Classes“ and „Objects“==&lt;br /&gt;
&lt;br /&gt;
C++ (and also Arduino) provides a specific feature that can solve our problem: Classes and Objects&lt;br /&gt;
&lt;br /&gt;
A Class predefines common qualities of a group of Objects. &amp;lt;br&amp;gt;&lt;br /&gt;
It for instance determines that every motor has the possibility to exert a certain amount of throttle. &amp;lt;br&amp;gt;&lt;br /&gt;
The corresponding program could look like this:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD3.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now the computer knows that there is a class called „Motor“.&amp;lt;br&amp;gt;&lt;br /&gt;
This class (class) provides a function called „setThrottle“ that is called as an argument by using a number (int) and that does not return anything (void).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Classes are Data-types===&lt;br /&gt;
&lt;br /&gt;
We can use our „Motor“ - class the same way we are using other data - types (int, long, float).&amp;lt;br&amp;gt;&lt;br /&gt;
The following lines use that quality in order to implement two motors:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD4.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Calling inner functions of a class (Methods)===&lt;br /&gt;
&lt;br /&gt;
Imagine we want to drive the left motor with full throttle whereas the right motor should stop completely. &amp;lt;br&amp;gt;&lt;br /&gt;
This can be expressed as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD5.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A positive side effect: your program gains readability by picking distinct names for your Objects and Methods.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Classes can contain other variables that can only be accessed „internally“===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do the Objects „leftMotor“ and „rightMotor“ know which pins they want to switch on and off?&lt;br /&gt;
&lt;br /&gt;
Until now our „Motor“ class is quite abstract since it does not contain this information. &amp;lt;br&amp;gt;&lt;br /&gt;
A class that should conduct practical actions needs further variables (concrete pin numbers) and lines of code that describe what to do exactly.&amp;lt;br&amp;gt;&lt;br /&gt;
We can simply include both things in the class definition:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD6.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do we include the pin numbers into the Object if they are not visible from the outside?&amp;lt;br&amp;gt;&lt;br /&gt;
We simply write a „setup“ Function for the class:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD7.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==A complete example ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to construct a complete example we only have to include the „speed“-Function (see description above):&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD8.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Organizing classes in separate files==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We can improve our program structure by putting classes in separate files:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;br&amp;gt;&lt;br /&gt;
Click on the arrow in the right corner in order to add a new file.&amp;lt;br&amp;gt;&lt;br /&gt;
Select „new Tab“.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:NewTabARDU.jpg]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
2.&amp;lt;br&amp;gt;&lt;br /&gt;
Enter a filename at the bottom of the window. &amp;lt;br&amp;gt;&lt;br /&gt;
It must end with &#039;.h&#039; – In our case it could be &#039;motorControl.h&#039;.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;br&amp;gt;&lt;br /&gt;
The first line of your code should be:&lt;br /&gt;
&lt;br /&gt;
&#039;#include „Arduino.h“&#039;&lt;br /&gt;
&lt;br /&gt;
This line &#039;links&#039; the file to the Arduino–specific features.&amp;lt;br&amp;gt;&lt;br /&gt;
Now we can include the code of our class.&lt;br /&gt;
&lt;br /&gt;
4.&amp;lt;br&amp;gt;&lt;br /&gt;
Go back to your main file.&amp;lt;br&amp;gt;&lt;br /&gt;
Now you have to &#039;link&#039; the new file to your main file in order to use the features of our class.&amp;lt;br&amp;gt;&lt;br /&gt;
Include the following line in the top of your main file&lt;br /&gt;
&lt;br /&gt;
&#039;#include &amp;quot;MotorControl.h“&#039;&lt;br /&gt;
&lt;br /&gt;
and write the rest of your program as usual.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==More Information==&lt;br /&gt;
&lt;br /&gt;
Classes can build up on each other (&amp;quot;inheritance&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
In the beginning we promised that it is possible to replace different motor drivers without changing the rest of the program.&lt;br /&gt;
Classes can indeed include other Objects in the form of „member variables“.&lt;br /&gt;
&lt;br /&gt;
C++ allows class declarations and the code for included Functions to be be placed in different files. &lt;br /&gt;
If you want to know more about that you can read this article about creating libraries in Arduino: [http://arduino.cc/en/Hacking/LibraryTutorial http://arduino.cc/en/Hacking/LibraryTutorial ]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Veja6203</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90149</id>
		<title>GMU:Functions and Classes (Arduino)</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90149"/>
		<updated>2017-03-28T13:50:22Z</updated>

		<summary type="html">&lt;p&gt;Veja6203: /* More Information */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Motivation==&lt;br /&gt;
&lt;br /&gt;
Soon after starting to write the program for your robot you will encounter some typical problems:&lt;br /&gt;
&lt;br /&gt;
* clarity: the bigger the program gets the harder it is to keep the general overview&lt;br /&gt;
* decoupling: you only want to change a certain part of the program without influencing all the rest&lt;br /&gt;
* recyclability: there are several similar parts in your robot for which you would like to reuse particular sections of your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These problems reach back to the beginning of programming and their solution is an art and a science at the same time.&lt;br /&gt;
It generally helps a lot to separate your program into single subunits that are relatively independent from each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example: Controlling Motors==&lt;br /&gt;
&lt;br /&gt;
The [http://arduino.cc/de/Reference/FunctionDeclaration function] is an enormous useful tool that can help you structuring your code. Functions allow you to sum up several operations under the same command. This command can be called again and again without knowing about or duplicating the included code. &lt;br /&gt;
&lt;br /&gt;
Here is an example for a function for setting the speed of a motor that is connected to an H-bridge:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD1.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now (and for every prospective motor movement) we only need to write one single line in order to for instance setting the left wheels speed:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD2.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This already saves us a lot of typing –&lt;br /&gt;
But one thing still seems quite laborious: we have to know the exact pin numbers every time we want to change the speed.&lt;br /&gt;
&lt;br /&gt;
Imagine a program in which similar function calls are distributed all over. &lt;br /&gt;
In case of a hardware update you would have to find every single function call and change the parameters manually. &lt;br /&gt;
This effort could surely be spent for more useful things..&lt;br /&gt;
&lt;br /&gt;
It would be ideal to find a way of calling a certain function that only offers the most useful parameters (like setting the speed) and which handles technical details (switching pins on and off) internally.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Possible solution: Data and code in one package – „Classes“ and „Objects“==&lt;br /&gt;
&lt;br /&gt;
C++ (and also Arduino) provides a specific feature that can solve our problem: Classes and Objects&lt;br /&gt;
&lt;br /&gt;
A Class predefines common qualities of a group of Objects. &lt;br /&gt;
It for instance determines that every motor has the possibility to exert a certain amount of throttle. &lt;br /&gt;
The corresponding program could look like this:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD3.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now the computer knows that there is a class called „Motor“.&lt;br /&gt;
This class (class) provides a function called „setThrottle“ that is called as an argument by using a number (int) and that does not return anything (void).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Classes are Data-types===&lt;br /&gt;
&lt;br /&gt;
We can use our „Motor“ - class the same way we are using other data - types (int, long, float).&amp;lt;p&amp;gt;&lt;br /&gt;
The following lines use that quality in order to implement two motors:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD4.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Calling inner functions of a class (Methods)===&lt;br /&gt;
&lt;br /&gt;
Imagine we want to drive the left motor with full throttle whereas the right motor should stop completely. &lt;br /&gt;
This can be expressed as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD5.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A positive side effect: your program gains readability by picking distinct names for your Objects and Methods.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Classes can contain other variables that can only be accessed „internally“===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do the Objects „leftMotor“ and „rightMotor“ know which pins they want to switch on and off?&lt;br /&gt;
&lt;br /&gt;
Until now our „Motor“ class is quite abstract since it does not contain this information. &lt;br /&gt;
A class that should conduct practical actions needs further variables (concrete pin numbers) and lines of code that describe what to do exactly.&lt;br /&gt;
We can simply include both things in the class definition:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD6.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do we include the pin numbers into the Object if they are not visible from the outside?&lt;br /&gt;
We simply write a „setup“ Function for the class:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD7.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==A complete example ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to construct a complete example we only have to include the „speed“-Function (see description above):&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD8.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Organizing classes in separate files==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We can improve our program structure by putting classes in separate files:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;br&amp;gt;&lt;br /&gt;
Click on the arrow in the right corner in order to add a new file.&amp;lt;br&amp;gt;&lt;br /&gt;
Select „new Tab“.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:NewTabARDU.jpg]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
2.&amp;lt;br&amp;gt;&lt;br /&gt;
Enter a filename at the bottom of the window. &amp;lt;br&amp;gt;&lt;br /&gt;
It must end with &#039;.h&#039; – In our case it could be &#039;motorControl.h&#039;.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;br&amp;gt;&lt;br /&gt;
The first line of your code should be:&lt;br /&gt;
&lt;br /&gt;
&#039;#include „Arduino.h“&#039;&lt;br /&gt;
&lt;br /&gt;
This line &#039;links&#039; the file to the Arduino–specific features.&amp;lt;br&amp;gt;&lt;br /&gt;
Now we can include the code of our class.&lt;br /&gt;
&lt;br /&gt;
4.&amp;lt;br&amp;gt;&lt;br /&gt;
Go back to your main file.&amp;lt;br&amp;gt;&lt;br /&gt;
Now you have to &#039;link&#039; the new file to your main file in order to use the features of our class.&amp;lt;br&amp;gt;&lt;br /&gt;
Include the following line in the top of your main file&lt;br /&gt;
&lt;br /&gt;
&#039;#include &amp;quot;MotorControl.h“&#039;&lt;br /&gt;
&lt;br /&gt;
and write the rest of your program as usual.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==More Information==&lt;br /&gt;
&lt;br /&gt;
Classes can build up on each other (&amp;quot;inheritance&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
In the beginning we promised that it is possible to replace different motor drivers without changing the rest of the program.&lt;br /&gt;
Classes can indeed include other Objects in the form of „member variables“.&lt;br /&gt;
&lt;br /&gt;
C++ allows class declarations and the code for included Functions to be be placed in different files. &lt;br /&gt;
If you want to know more about that you can read this article about creating libraries in Arduino: [http://arduino.cc/en/Hacking/LibraryTutorial http://arduino.cc/en/Hacking/LibraryTutorial ]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Veja6203</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90148</id>
		<title>GMU:Functions and Classes (Arduino)</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90148"/>
		<updated>2017-03-28T13:50:06Z</updated>

		<summary type="html">&lt;p&gt;Veja6203: /* Organizing classes in separate files */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Motivation==&lt;br /&gt;
&lt;br /&gt;
Soon after starting to write the program for your robot you will encounter some typical problems:&lt;br /&gt;
&lt;br /&gt;
* clarity: the bigger the program gets the harder it is to keep the general overview&lt;br /&gt;
* decoupling: you only want to change a certain part of the program without influencing all the rest&lt;br /&gt;
* recyclability: there are several similar parts in your robot for which you would like to reuse particular sections of your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These problems reach back to the beginning of programming and their solution is an art and a science at the same time.&lt;br /&gt;
It generally helps a lot to separate your program into single subunits that are relatively independent from each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example: Controlling Motors==&lt;br /&gt;
&lt;br /&gt;
The [http://arduino.cc/de/Reference/FunctionDeclaration function] is an enormous useful tool that can help you structuring your code. Functions allow you to sum up several operations under the same command. This command can be called again and again without knowing about or duplicating the included code. &lt;br /&gt;
&lt;br /&gt;
Here is an example for a function for setting the speed of a motor that is connected to an H-bridge:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD1.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now (and for every prospective motor movement) we only need to write one single line in order to for instance setting the left wheels speed:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD2.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This already saves us a lot of typing –&lt;br /&gt;
But one thing still seems quite laborious: we have to know the exact pin numbers every time we want to change the speed.&lt;br /&gt;
&lt;br /&gt;
Imagine a program in which similar function calls are distributed all over. &lt;br /&gt;
In case of a hardware update you would have to find every single function call and change the parameters manually. &lt;br /&gt;
This effort could surely be spent for more useful things..&lt;br /&gt;
&lt;br /&gt;
It would be ideal to find a way of calling a certain function that only offers the most useful parameters (like setting the speed) and which handles technical details (switching pins on and off) internally.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Possible solution: Data and code in one package – „Classes“ and „Objects“==&lt;br /&gt;
&lt;br /&gt;
C++ (and also Arduino) provides a specific feature that can solve our problem: Classes and Objects&lt;br /&gt;
&lt;br /&gt;
A Class predefines common qualities of a group of Objects. &lt;br /&gt;
It for instance determines that every motor has the possibility to exert a certain amount of throttle. &lt;br /&gt;
The corresponding program could look like this:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD3.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now the computer knows that there is a class called „Motor“.&lt;br /&gt;
This class (class) provides a function called „setThrottle“ that is called as an argument by using a number (int) and that does not return anything (void).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Classes are Data-types===&lt;br /&gt;
&lt;br /&gt;
We can use our „Motor“ - class the same way we are using other data - types (int, long, float).&amp;lt;p&amp;gt;&lt;br /&gt;
The following lines use that quality in order to implement two motors:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD4.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Calling inner functions of a class (Methods)===&lt;br /&gt;
&lt;br /&gt;
Imagine we want to drive the left motor with full throttle whereas the right motor should stop completely. &lt;br /&gt;
This can be expressed as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD5.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A positive side effect: your program gains readability by picking distinct names for your Objects and Methods.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Classes can contain other variables that can only be accessed „internally“===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do the Objects „leftMotor“ and „rightMotor“ know which pins they want to switch on and off?&lt;br /&gt;
&lt;br /&gt;
Until now our „Motor“ class is quite abstract since it does not contain this information. &lt;br /&gt;
A class that should conduct practical actions needs further variables (concrete pin numbers) and lines of code that describe what to do exactly.&lt;br /&gt;
We can simply include both things in the class definition:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD6.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do we include the pin numbers into the Object if they are not visible from the outside?&lt;br /&gt;
We simply write a „setup“ Function for the class:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD7.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==A complete example ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to construct a complete example we only have to include the „speed“-Function (see description above):&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD8.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Organizing classes in separate files==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We can improve our program structure by putting classes in separate files:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;br&amp;gt;&lt;br /&gt;
Click on the arrow in the right corner in order to add a new file.&amp;lt;br&amp;gt;&lt;br /&gt;
Select „new Tab“.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:NewTabARDU.jpg]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
2.&amp;lt;br&amp;gt;&lt;br /&gt;
Enter a filename at the bottom of the window. &amp;lt;br&amp;gt;&lt;br /&gt;
It must end with &#039;.h&#039; – In our case it could be &#039;motorControl.h&#039;.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;br&amp;gt;&lt;br /&gt;
The first line of your code should be:&lt;br /&gt;
&lt;br /&gt;
&#039;#include „Arduino.h“&#039;&lt;br /&gt;
&lt;br /&gt;
This line &#039;links&#039; the file to the Arduino–specific features.&amp;lt;br&amp;gt;&lt;br /&gt;
Now we can include the code of our class.&lt;br /&gt;
&lt;br /&gt;
4.&amp;lt;br&amp;gt;&lt;br /&gt;
Go back to your main file.&amp;lt;br&amp;gt;&lt;br /&gt;
Now you have to &#039;link&#039; the new file to your main file in order to use the features of our class.&amp;lt;br&amp;gt;&lt;br /&gt;
Include the following line in the top of your main file&lt;br /&gt;
&lt;br /&gt;
&#039;#include &amp;quot;MotorControl.h“&#039;&lt;br /&gt;
&lt;br /&gt;
and write the rest of your program as usual.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==More Information==&lt;br /&gt;
&lt;br /&gt;
Classes can build up on each other (inheritance)&lt;br /&gt;
&lt;br /&gt;
In the beginning we promised that it is possible to replace different motor drivers without changing the rest of the program.&lt;br /&gt;
Classes can indeed include other Objects in the form of „member variables“.&lt;br /&gt;
&lt;br /&gt;
C++ allows class declarations and the code for included Functions to be be placed in different files. &lt;br /&gt;
If you want to know more about that you can read this article about creating libraries in Arduino: [http://arduino.cc/en/Hacking/LibraryTutorial http://arduino.cc/en/Hacking/LibraryTutorial ]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Veja6203</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90147</id>
		<title>GMU:Functions and Classes (Arduino)</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90147"/>
		<updated>2017-03-28T13:49:46Z</updated>

		<summary type="html">&lt;p&gt;Veja6203: /* Organizing classes in separate files */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Motivation==&lt;br /&gt;
&lt;br /&gt;
Soon after starting to write the program for your robot you will encounter some typical problems:&lt;br /&gt;
&lt;br /&gt;
* clarity: the bigger the program gets the harder it is to keep the general overview&lt;br /&gt;
* decoupling: you only want to change a certain part of the program without influencing all the rest&lt;br /&gt;
* recyclability: there are several similar parts in your robot for which you would like to reuse particular sections of your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These problems reach back to the beginning of programming and their solution is an art and a science at the same time.&lt;br /&gt;
It generally helps a lot to separate your program into single subunits that are relatively independent from each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example: Controlling Motors==&lt;br /&gt;
&lt;br /&gt;
The [http://arduino.cc/de/Reference/FunctionDeclaration function] is an enormous useful tool that can help you structuring your code. Functions allow you to sum up several operations under the same command. This command can be called again and again without knowing about or duplicating the included code. &lt;br /&gt;
&lt;br /&gt;
Here is an example for a function for setting the speed of a motor that is connected to an H-bridge:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD1.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now (and for every prospective motor movement) we only need to write one single line in order to for instance setting the left wheels speed:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD2.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This already saves us a lot of typing –&lt;br /&gt;
But one thing still seems quite laborious: we have to know the exact pin numbers every time we want to change the speed.&lt;br /&gt;
&lt;br /&gt;
Imagine a program in which similar function calls are distributed all over. &lt;br /&gt;
In case of a hardware update you would have to find every single function call and change the parameters manually. &lt;br /&gt;
This effort could surely be spent for more useful things..&lt;br /&gt;
&lt;br /&gt;
It would be ideal to find a way of calling a certain function that only offers the most useful parameters (like setting the speed) and which handles technical details (switching pins on and off) internally.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Possible solution: Data and code in one package – „Classes“ and „Objects“==&lt;br /&gt;
&lt;br /&gt;
C++ (and also Arduino) provides a specific feature that can solve our problem: Classes and Objects&lt;br /&gt;
&lt;br /&gt;
A Class predefines common qualities of a group of Objects. &lt;br /&gt;
It for instance determines that every motor has the possibility to exert a certain amount of throttle. &lt;br /&gt;
The corresponding program could look like this:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD3.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now the computer knows that there is a class called „Motor“.&lt;br /&gt;
This class (class) provides a function called „setThrottle“ that is called as an argument by using a number (int) and that does not return anything (void).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Classes are Data-types===&lt;br /&gt;
&lt;br /&gt;
We can use our „Motor“ - class the same way we are using other data - types (int, long, float).&amp;lt;p&amp;gt;&lt;br /&gt;
The following lines use that quality in order to implement two motors:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD4.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Calling inner functions of a class (Methods)===&lt;br /&gt;
&lt;br /&gt;
Imagine we want to drive the left motor with full throttle whereas the right motor should stop completely. &lt;br /&gt;
This can be expressed as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD5.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A positive side effect: your program gains readability by picking distinct names for your Objects and Methods.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Classes can contain other variables that can only be accessed „internally“===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do the Objects „leftMotor“ and „rightMotor“ know which pins they want to switch on and off?&lt;br /&gt;
&lt;br /&gt;
Until now our „Motor“ class is quite abstract since it does not contain this information. &lt;br /&gt;
A class that should conduct practical actions needs further variables (concrete pin numbers) and lines of code that describe what to do exactly.&lt;br /&gt;
We can simply include both things in the class definition:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD6.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do we include the pin numbers into the Object if they are not visible from the outside?&lt;br /&gt;
We simply write a „setup“ Function for the class:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD7.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==A complete example ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to construct a complete example we only have to include the „speed“-Function (see description above):&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD8.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Organizing classes in separate files==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We can improve our program structure by putting classes in separate files:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;br&amp;gt;&lt;br /&gt;
Click on the arrow in the right corner in order to add a new file.&amp;lt;br&amp;gt;&lt;br /&gt;
Select „new Tab“.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:NewTabARDU.jpg]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
2.&amp;lt;br&amp;gt;&lt;br /&gt;
Enter a filename at the bottom of the window. &amp;lt;br&amp;gt;&lt;br /&gt;
It must end with &#039;.h&#039; – In our case it could be &#039;motorControl.h&#039;.&lt;br /&gt;
&lt;br /&gt;
3.&amp;lt;br&amp;gt;&lt;br /&gt;
The first line of your code should be:&lt;br /&gt;
&lt;br /&gt;
&#039;#include „Arduino.h“&#039;&lt;br /&gt;
&lt;br /&gt;
This line &#039;links&#039; the file to the Arduino–specific features.&amp;lt;br&amp;gt;&lt;br /&gt;
Now we can include the code of our class.&lt;br /&gt;
&lt;br /&gt;
4.&amp;lt;br&amp;gt;&lt;br /&gt;
Go back to your main file.&amp;lt;br&amp;gt;&lt;br /&gt;
Now you have to &#039;link&#039; the new file to your main file in order to use the features of our class.&amp;lt;br&amp;gt;&lt;br /&gt;
Include the following line in the top of your main file&lt;br /&gt;
&lt;br /&gt;
&#039;#include &amp;quot;MotorControl.h“&#039;&lt;br /&gt;
&lt;br /&gt;
and write the rest of your program as usual.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==More Information==&lt;br /&gt;
&lt;br /&gt;
Classes can build up on each other (inheritance)&lt;br /&gt;
&lt;br /&gt;
In the beginning we promised that it is possible to replace different motor drivers without changing the rest of the program.&lt;br /&gt;
Classes can indeed include other Objects in the form of „member variables“.&lt;br /&gt;
&lt;br /&gt;
C++ allows class declarations and the code for included Functions to be be placed in different files. &lt;br /&gt;
If you want to know more about that you can read this article about creating libraries in Arduino: [http://arduino.cc/en/Hacking/LibraryTutorial http://arduino.cc/en/Hacking/LibraryTutorial ]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Veja6203</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90146</id>
		<title>GMU:Functions and Classes (Arduino)</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90146"/>
		<updated>2017-03-28T13:47:48Z</updated>

		<summary type="html">&lt;p&gt;Veja6203: /* Organizing classes in separate files */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Motivation==&lt;br /&gt;
&lt;br /&gt;
Soon after starting to write the program for your robot you will encounter some typical problems:&lt;br /&gt;
&lt;br /&gt;
* clarity: the bigger the program gets the harder it is to keep the general overview&lt;br /&gt;
* decoupling: you only want to change a certain part of the program without influencing all the rest&lt;br /&gt;
* recyclability: there are several similar parts in your robot for which you would like to reuse particular sections of your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These problems reach back to the beginning of programming and their solution is an art and a science at the same time.&lt;br /&gt;
It generally helps a lot to separate your program into single subunits that are relatively independent from each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example: Controlling Motors==&lt;br /&gt;
&lt;br /&gt;
The [http://arduino.cc/de/Reference/FunctionDeclaration function] is an enormous useful tool that can help you structuring your code. Functions allow you to sum up several operations under the same command. This command can be called again and again without knowing about or duplicating the included code. &lt;br /&gt;
&lt;br /&gt;
Here is an example for a function for setting the speed of a motor that is connected to an H-bridge:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD1.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now (and for every prospective motor movement) we only need to write one single line in order to for instance setting the left wheels speed:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD2.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This already saves us a lot of typing –&lt;br /&gt;
But one thing still seems quite laborious: we have to know the exact pin numbers every time we want to change the speed.&lt;br /&gt;
&lt;br /&gt;
Imagine a program in which similar function calls are distributed all over. &lt;br /&gt;
In case of a hardware update you would have to find every single function call and change the parameters manually. &lt;br /&gt;
This effort could surely be spent for more useful things..&lt;br /&gt;
&lt;br /&gt;
It would be ideal to find a way of calling a certain function that only offers the most useful parameters (like setting the speed) and which handles technical details (switching pins on and off) internally.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Possible solution: Data and code in one package – „Classes“ and „Objects“==&lt;br /&gt;
&lt;br /&gt;
C++ (and also Arduino) provides a specific feature that can solve our problem: Classes and Objects&lt;br /&gt;
&lt;br /&gt;
A Class predefines common qualities of a group of Objects. &lt;br /&gt;
It for instance determines that every motor has the possibility to exert a certain amount of throttle. &lt;br /&gt;
The corresponding program could look like this:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD3.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now the computer knows that there is a class called „Motor“.&lt;br /&gt;
This class (class) provides a function called „setThrottle“ that is called as an argument by using a number (int) and that does not return anything (void).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Classes are Data-types===&lt;br /&gt;
&lt;br /&gt;
We can use our „Motor“ - class the same way we are using other data - types (int, long, float).&amp;lt;p&amp;gt;&lt;br /&gt;
The following lines use that quality in order to implement two motors:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD4.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Calling inner functions of a class (Methods)===&lt;br /&gt;
&lt;br /&gt;
Imagine we want to drive the left motor with full throttle whereas the right motor should stop completely. &lt;br /&gt;
This can be expressed as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD5.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A positive side effect: your program gains readability by picking distinct names for your Objects and Methods.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Classes can contain other variables that can only be accessed „internally“===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do the Objects „leftMotor“ and „rightMotor“ know which pins they want to switch on and off?&lt;br /&gt;
&lt;br /&gt;
Until now our „Motor“ class is quite abstract since it does not contain this information. &lt;br /&gt;
A class that should conduct practical actions needs further variables (concrete pin numbers) and lines of code that describe what to do exactly.&lt;br /&gt;
We can simply include both things in the class definition:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD6.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do we include the pin numbers into the Object if they are not visible from the outside?&lt;br /&gt;
We simply write a „setup“ Function for the class:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD7.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==A complete example ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to construct a complete example we only have to include the „speed“-Function (see description above):&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD8.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Organizing classes in separate files==&lt;br /&gt;
&lt;br /&gt;
We can improve our program structure by putting classes in separate files:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1. &lt;br /&gt;
Click on the arrow in the right corner in order to add a new file.&lt;br /&gt;
Select „new Tab“.&lt;br /&gt;
&lt;br /&gt;
[[File:NewTabARDU.jpg]]&lt;br /&gt;
&lt;br /&gt;
2.&lt;br /&gt;
Enter a filename at the bottom of the window. &lt;br /&gt;
It must end with .h – In our case it could be &#039;motorControl.h&#039;.&lt;br /&gt;
&lt;br /&gt;
3.&lt;br /&gt;
The first line of your code should be:&lt;br /&gt;
&lt;br /&gt;
&#039;#include „Arduino.h“&#039;&lt;br /&gt;
&lt;br /&gt;
This line &#039;links&#039; the file to the Arduino–specific features.&lt;br /&gt;
Now we can include the code of our class.&lt;br /&gt;
&lt;br /&gt;
4.&lt;br /&gt;
Go back to your main file.&lt;br /&gt;
Now you have to &#039;link&#039; the new file to your main file in order to use the features of our class.&lt;br /&gt;
Include the following line in the top of your main file&lt;br /&gt;
&lt;br /&gt;
&#039;#include &amp;quot;MotorControl.h“&#039;&lt;br /&gt;
&lt;br /&gt;
and write the rest of your program as usual.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==More Information==&lt;br /&gt;
&lt;br /&gt;
Classes can build up on each other (inheritance)&lt;br /&gt;
&lt;br /&gt;
In the beginning we promised that it is possible to replace different motor drivers without changing the rest of the program.&lt;br /&gt;
Classes can indeed include other Objects in the form of „member variables“.&lt;br /&gt;
&lt;br /&gt;
C++ allows class declarations and the code for included Functions to be be placed in different files. &lt;br /&gt;
If you want to know more about that you can read this article about creating libraries in Arduino: [http://arduino.cc/en/Hacking/LibraryTutorial http://arduino.cc/en/Hacking/LibraryTutorial ]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Veja6203</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90145</id>
		<title>GMU:Functions and Classes (Arduino)</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90145"/>
		<updated>2017-03-28T13:46:38Z</updated>

		<summary type="html">&lt;p&gt;Veja6203: /* Organizing classes in separate files */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Motivation==&lt;br /&gt;
&lt;br /&gt;
Soon after starting to write the program for your robot you will encounter some typical problems:&lt;br /&gt;
&lt;br /&gt;
* clarity: the bigger the program gets the harder it is to keep the general overview&lt;br /&gt;
* decoupling: you only want to change a certain part of the program without influencing all the rest&lt;br /&gt;
* recyclability: there are several similar parts in your robot for which you would like to reuse particular sections of your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These problems reach back to the beginning of programming and their solution is an art and a science at the same time.&lt;br /&gt;
It generally helps a lot to separate your program into single subunits that are relatively independent from each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example: Controlling Motors==&lt;br /&gt;
&lt;br /&gt;
The [http://arduino.cc/de/Reference/FunctionDeclaration function] is an enormous useful tool that can help you structuring your code. Functions allow you to sum up several operations under the same command. This command can be called again and again without knowing about or duplicating the included code. &lt;br /&gt;
&lt;br /&gt;
Here is an example for a function for setting the speed of a motor that is connected to an H-bridge:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD1.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now (and for every prospective motor movement) we only need to write one single line in order to for instance setting the left wheels speed:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD2.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This already saves us a lot of typing –&lt;br /&gt;
But one thing still seems quite laborious: we have to know the exact pin numbers every time we want to change the speed.&lt;br /&gt;
&lt;br /&gt;
Imagine a program in which similar function calls are distributed all over. &lt;br /&gt;
In case of a hardware update you would have to find every single function call and change the parameters manually. &lt;br /&gt;
This effort could surely be spent for more useful things..&lt;br /&gt;
&lt;br /&gt;
It would be ideal to find a way of calling a certain function that only offers the most useful parameters (like setting the speed) and which handles technical details (switching pins on and off) internally.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Possible solution: Data and code in one package – „Classes“ and „Objects“==&lt;br /&gt;
&lt;br /&gt;
C++ (and also Arduino) provides a specific feature that can solve our problem: Classes and Objects&lt;br /&gt;
&lt;br /&gt;
A Class predefines common qualities of a group of Objects. &lt;br /&gt;
It for instance determines that every motor has the possibility to exert a certain amount of throttle. &lt;br /&gt;
The corresponding program could look like this:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD3.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now the computer knows that there is a class called „Motor“.&lt;br /&gt;
This class (class) provides a function called „setThrottle“ that is called as an argument by using a number (int) and that does not return anything (void).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Classes are Data-types===&lt;br /&gt;
&lt;br /&gt;
We can use our „Motor“ - class the same way we are using other data - types (int, long, float).&amp;lt;p&amp;gt;&lt;br /&gt;
The following lines use that quality in order to implement two motors:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD4.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Calling inner functions of a class (Methods)===&lt;br /&gt;
&lt;br /&gt;
Imagine we want to drive the left motor with full throttle whereas the right motor should stop completely. &lt;br /&gt;
This can be expressed as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD5.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A positive side effect: your program gains readability by picking distinct names for your Objects and Methods.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Classes can contain other variables that can only be accessed „internally“===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do the Objects „leftMotor“ and „rightMotor“ know which pins they want to switch on and off?&lt;br /&gt;
&lt;br /&gt;
Until now our „Motor“ class is quite abstract since it does not contain this information. &lt;br /&gt;
A class that should conduct practical actions needs further variables (concrete pin numbers) and lines of code that describe what to do exactly.&lt;br /&gt;
We can simply include both things in the class definition:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD6.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do we include the pin numbers into the Object if they are not visible from the outside?&lt;br /&gt;
We simply write a „setup“ Function for the class:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD7.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==A complete example ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to construct a complete example we only have to include the „speed“-Function (see description above):&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD8.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Organizing classes in separate files==&lt;br /&gt;
&lt;br /&gt;
We can improve our program structure by putting classes in separate files:&lt;br /&gt;
&lt;br /&gt;
:1. &lt;br /&gt;
:Click on the arrow in the right corner in order to add a new file.&lt;br /&gt;
:Select „new Tab“.&lt;br /&gt;
&lt;br /&gt;
:[[File:NewTabARDU.jpg]]&lt;br /&gt;
&lt;br /&gt;
:2.&lt;br /&gt;
:Enter a filename at the bottom of the window. &lt;br /&gt;
:It must end with .h – In our case it could be &#039;motorControl.h&#039;.&lt;br /&gt;
&lt;br /&gt;
:3.&lt;br /&gt;
:The first line of your code should be:&lt;br /&gt;
&lt;br /&gt;
:&#039;#include „Arduino.h“&#039;&lt;br /&gt;
&lt;br /&gt;
:This line &#039;links&#039; the file to the Arduino–specific features.&lt;br /&gt;
:Now we can include the code of our class.&lt;br /&gt;
&lt;br /&gt;
:4.&lt;br /&gt;
:Go back to your main file.&lt;br /&gt;
:Now you have to &#039;link&#039; the new file to your main file in order to use the features of our class.&lt;br /&gt;
:Include the following line in the top of your main file&lt;br /&gt;
&lt;br /&gt;
:&#039;#include &amp;quot;MotorControl.h“&#039;&lt;br /&gt;
&lt;br /&gt;
:and write the rest of your program as usual.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==More Information==&lt;br /&gt;
&lt;br /&gt;
Classes can build up on each other (inheritance)&lt;br /&gt;
&lt;br /&gt;
In the beginning we promised that it is possible to replace different motor drivers without changing the rest of the program.&lt;br /&gt;
Classes can indeed include other Objects in the form of „member variables“.&lt;br /&gt;
&lt;br /&gt;
C++ allows class declarations and the code for included Functions to be be placed in different files. &lt;br /&gt;
If you want to know more about that you can read this article about creating libraries in Arduino: [http://arduino.cc/en/Hacking/LibraryTutorial http://arduino.cc/en/Hacking/LibraryTutorial ]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Veja6203</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90144</id>
		<title>GMU:Functions and Classes (Arduino)</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90144"/>
		<updated>2017-03-28T13:45:40Z</updated>

		<summary type="html">&lt;p&gt;Veja6203: /* More details on the concept */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Motivation==&lt;br /&gt;
&lt;br /&gt;
Soon after starting to write the program for your robot you will encounter some typical problems:&lt;br /&gt;
&lt;br /&gt;
* clarity: the bigger the program gets the harder it is to keep the general overview&lt;br /&gt;
* decoupling: you only want to change a certain part of the program without influencing all the rest&lt;br /&gt;
* recyclability: there are several similar parts in your robot for which you would like to reuse particular sections of your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These problems reach back to the beginning of programming and their solution is an art and a science at the same time.&lt;br /&gt;
It generally helps a lot to separate your program into single subunits that are relatively independent from each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example: Controlling Motors==&lt;br /&gt;
&lt;br /&gt;
The [http://arduino.cc/de/Reference/FunctionDeclaration function] is an enormous useful tool that can help you structuring your code. Functions allow you to sum up several operations under the same command. This command can be called again and again without knowing about or duplicating the included code. &lt;br /&gt;
&lt;br /&gt;
Here is an example for a function for setting the speed of a motor that is connected to an H-bridge:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD1.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now (and for every prospective motor movement) we only need to write one single line in order to for instance setting the left wheels speed:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD2.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This already saves us a lot of typing –&lt;br /&gt;
But one thing still seems quite laborious: we have to know the exact pin numbers every time we want to change the speed.&lt;br /&gt;
&lt;br /&gt;
Imagine a program in which similar function calls are distributed all over. &lt;br /&gt;
In case of a hardware update you would have to find every single function call and change the parameters manually. &lt;br /&gt;
This effort could surely be spent for more useful things..&lt;br /&gt;
&lt;br /&gt;
It would be ideal to find a way of calling a certain function that only offers the most useful parameters (like setting the speed) and which handles technical details (switching pins on and off) internally.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Possible solution: Data and code in one package – „Classes“ and „Objects“==&lt;br /&gt;
&lt;br /&gt;
C++ (and also Arduino) provides a specific feature that can solve our problem: Classes and Objects&lt;br /&gt;
&lt;br /&gt;
A Class predefines common qualities of a group of Objects. &lt;br /&gt;
It for instance determines that every motor has the possibility to exert a certain amount of throttle. &lt;br /&gt;
The corresponding program could look like this:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD3.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now the computer knows that there is a class called „Motor“.&lt;br /&gt;
This class (class) provides a function called „setThrottle“ that is called as an argument by using a number (int) and that does not return anything (void).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Classes are Data-types===&lt;br /&gt;
&lt;br /&gt;
We can use our „Motor“ - class the same way we are using other data - types (int, long, float).&amp;lt;p&amp;gt;&lt;br /&gt;
The following lines use that quality in order to implement two motors:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD4.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Calling inner functions of a class (Methods)===&lt;br /&gt;
&lt;br /&gt;
Imagine we want to drive the left motor with full throttle whereas the right motor should stop completely. &lt;br /&gt;
This can be expressed as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD5.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A positive side effect: your program gains readability by picking distinct names for your Objects and Methods.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Classes can contain other variables that can only be accessed „internally“===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do the Objects „leftMotor“ and „rightMotor“ know which pins they want to switch on and off?&lt;br /&gt;
&lt;br /&gt;
Until now our „Motor“ class is quite abstract since it does not contain this information. &lt;br /&gt;
A class that should conduct practical actions needs further variables (concrete pin numbers) and lines of code that describe what to do exactly.&lt;br /&gt;
We can simply include both things in the class definition:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD6.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do we include the pin numbers into the Object if they are not visible from the outside?&lt;br /&gt;
We simply write a „setup“ Function for the class:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD7.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==A complete example ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to construct a complete example we only have to include the „speed“-Function (see description above):&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD8.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Organizing classes in separate files==&lt;br /&gt;
&lt;br /&gt;
We can improve our program structure by putting classes in separate files:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:1. &lt;br /&gt;
:Click on the arrow in the right corner in order to add a new file.&lt;br /&gt;
:Select „new Tab“.&lt;br /&gt;
&lt;br /&gt;
:[[File:NewTabARDU.jpg]]&lt;br /&gt;
&lt;br /&gt;
:2.&lt;br /&gt;
:Enter a filename at the bottom of the window. &lt;br /&gt;
:It must end with .h – In our case it could be &#039;motorControl.h&#039;.&lt;br /&gt;
&lt;br /&gt;
:3.&lt;br /&gt;
:The first line of your code should be:&lt;br /&gt;
&lt;br /&gt;
:&#039;#include „Arduino.h“&#039;&lt;br /&gt;
&lt;br /&gt;
:This line &#039;links&#039; the file to the Arduino–specific features.&lt;br /&gt;
:Now we can include the code of our class.&lt;br /&gt;
&lt;br /&gt;
:4.&lt;br /&gt;
:Go back to your main file.&lt;br /&gt;
:Now you have to &#039;link&#039; the new file to your main file in order to use the features of our class.&lt;br /&gt;
:Include the following line in the top of your main file&lt;br /&gt;
&lt;br /&gt;
:&#039;#include &amp;quot;MotorControl.h“&#039;&lt;br /&gt;
&lt;br /&gt;
:and write the rest of your program as usual.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==More Information==&lt;br /&gt;
&lt;br /&gt;
Classes can build up on each other (inheritance)&lt;br /&gt;
&lt;br /&gt;
In the beginning we promised that it is possible to replace different motor drivers without changing the rest of the program.&lt;br /&gt;
Classes can indeed include other Objects in the form of „member variables“.&lt;br /&gt;
&lt;br /&gt;
C++ allows class declarations and the code for included Functions to be be placed in different files. &lt;br /&gt;
If you want to know more about that you can read this article about creating libraries in Arduino: [http://arduino.cc/en/Hacking/LibraryTutorial http://arduino.cc/en/Hacking/LibraryTutorial ]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Veja6203</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90143</id>
		<title>GMU:Functions and Classes (Arduino)</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90143"/>
		<updated>2017-03-28T13:45:17Z</updated>

		<summary type="html">&lt;p&gt;Veja6203: /* Organizing classes in separate files */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Motivation==&lt;br /&gt;
&lt;br /&gt;
Soon after starting to write the program for your robot you will encounter some typical problems:&lt;br /&gt;
&lt;br /&gt;
* clarity: the bigger the program gets the harder it is to keep the general overview&lt;br /&gt;
* decoupling: you only want to change a certain part of the program without influencing all the rest&lt;br /&gt;
* recyclability: there are several similar parts in your robot for which you would like to reuse particular sections of your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These problems reach back to the beginning of programming and their solution is an art and a science at the same time.&lt;br /&gt;
It generally helps a lot to separate your program into single subunits that are relatively independent from each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example: Controlling Motors==&lt;br /&gt;
&lt;br /&gt;
The [http://arduino.cc/de/Reference/FunctionDeclaration function] is an enormous useful tool that can help you structuring your code. Functions allow you to sum up several operations under the same command. This command can be called again and again without knowing about or duplicating the included code. &lt;br /&gt;
&lt;br /&gt;
Here is an example for a function for setting the speed of a motor that is connected to an H-bridge:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD1.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now (and for every prospective motor movement) we only need to write one single line in order to for instance setting the left wheels speed:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD2.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This already saves us a lot of typing –&lt;br /&gt;
But one thing still seems quite laborious: we have to know the exact pin numbers every time we want to change the speed.&lt;br /&gt;
&lt;br /&gt;
Imagine a program in which similar function calls are distributed all over. &lt;br /&gt;
In case of a hardware update you would have to find every single function call and change the parameters manually. &lt;br /&gt;
This effort could surely be spent for more useful things..&lt;br /&gt;
&lt;br /&gt;
It would be ideal to find a way of calling a certain function that only offers the most useful parameters (like setting the speed) and which handles technical details (switching pins on and off) internally.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Possible solution: Data and code in one package – „Classes“ and „Objects“==&lt;br /&gt;
&lt;br /&gt;
C++ (and also Arduino) provides a specific feature that can solve our problem: Classes and Objects&lt;br /&gt;
&lt;br /&gt;
A Class predefines common qualities of a group of Objects. &lt;br /&gt;
It for instance determines that every motor has the possibility to exert a certain amount of throttle. &lt;br /&gt;
The corresponding program could look like this:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD3.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now the computer knows that there is a class called „Motor“.&lt;br /&gt;
This class (class) provides a function called „setThrottle“ that is called as an argument by using a number (int) and that does not return anything (void).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Classes are Data-types===&lt;br /&gt;
&lt;br /&gt;
We can use our „Motor“ - class the same way we are using other data - types (int, long, float).&amp;lt;p&amp;gt;&lt;br /&gt;
The following lines use that quality in order to implement two motors:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD4.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Calling inner functions of a class (Methods)===&lt;br /&gt;
&lt;br /&gt;
Imagine we want to drive the left motor with full throttle whereas the right motor should stop completely. &lt;br /&gt;
This can be expressed as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD5.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A positive side effect: your program gains readability by picking distinct names for your Objects and Methods.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Classes can contain other variables that can only be accessed „internally“===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do the Objects „leftMotor“ and „rightMotor“ know which pins they want to switch on and off?&lt;br /&gt;
&lt;br /&gt;
Until now our „Motor“ class is quite abstract since it does not contain this information. &lt;br /&gt;
A class that should conduct practical actions needs further variables (concrete pin numbers) and lines of code that describe what to do exactly.&lt;br /&gt;
We can simply include both things in the class definition:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD6.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do we include the pin numbers into the Object if they are not visible from the outside?&lt;br /&gt;
We simply write a „setup“ Function for the class:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD7.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==A complete example ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to construct a complete example we only have to include the „speed“-Function (see description above):&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD8.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Organizing classes in separate files==&lt;br /&gt;
&lt;br /&gt;
We can improve our program structure by putting classes in separate files:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:1. &lt;br /&gt;
:Click on the arrow in the right corner in order to add a new file.&lt;br /&gt;
:Select „new Tab“.&lt;br /&gt;
&lt;br /&gt;
:[[File:NewTabARDU.jpg]]&lt;br /&gt;
&lt;br /&gt;
:2.&lt;br /&gt;
:Enter a filename at the bottom of the window. &lt;br /&gt;
:It must end with .h – In our case it could be &#039;motorControl.h&#039;.&lt;br /&gt;
&lt;br /&gt;
:3.&lt;br /&gt;
:The first line of your code should be:&lt;br /&gt;
&lt;br /&gt;
:&#039;#include „Arduino.h“&#039;&lt;br /&gt;
&lt;br /&gt;
:This line &#039;links&#039; the file to the Arduino–specific features.&lt;br /&gt;
:Now we can include the code of our class.&lt;br /&gt;
&lt;br /&gt;
:4.&lt;br /&gt;
:Go back to your main file.&lt;br /&gt;
:Now you have to &#039;link&#039; the new file to your main file in order to use the features of our class.&lt;br /&gt;
:Include the following line in the top of your main file&lt;br /&gt;
&lt;br /&gt;
:&#039;#include &amp;quot;MotorControl.h“&#039;&lt;br /&gt;
&lt;br /&gt;
:and write the rest of your program as usual.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==More details on the concept==&lt;br /&gt;
&lt;br /&gt;
Classes can build up on each other (inheritance)&lt;br /&gt;
&lt;br /&gt;
In the beginning we promised that it is possible to replace different motor drivers without changing the rest of the program.&lt;br /&gt;
Classes can indeed include other Objects in the form of „member variables“.&lt;br /&gt;
&lt;br /&gt;
C++ allows class declarations and the code for included Functions to be be placed in different files. &lt;br /&gt;
If you want to know more about that you can read this article about creating libraries in Arduino: [http://arduino.cc/en/Hacking/LibraryTutorial http://arduino.cc/en/Hacking/LibraryTutorial ]&lt;/div&gt;</summary>
		<author><name>Veja6203</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90142</id>
		<title>GMU:Functions and Classes (Arduino)</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90142"/>
		<updated>2017-03-28T13:45:05Z</updated>

		<summary type="html">&lt;p&gt;Veja6203: /* Organizing classes in separate files */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Motivation==&lt;br /&gt;
&lt;br /&gt;
Soon after starting to write the program for your robot you will encounter some typical problems:&lt;br /&gt;
&lt;br /&gt;
* clarity: the bigger the program gets the harder it is to keep the general overview&lt;br /&gt;
* decoupling: you only want to change a certain part of the program without influencing all the rest&lt;br /&gt;
* recyclability: there are several similar parts in your robot for which you would like to reuse particular sections of your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These problems reach back to the beginning of programming and their solution is an art and a science at the same time.&lt;br /&gt;
It generally helps a lot to separate your program into single subunits that are relatively independent from each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example: Controlling Motors==&lt;br /&gt;
&lt;br /&gt;
The [http://arduino.cc/de/Reference/FunctionDeclaration function] is an enormous useful tool that can help you structuring your code. Functions allow you to sum up several operations under the same command. This command can be called again and again without knowing about or duplicating the included code. &lt;br /&gt;
&lt;br /&gt;
Here is an example for a function for setting the speed of a motor that is connected to an H-bridge:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD1.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now (and for every prospective motor movement) we only need to write one single line in order to for instance setting the left wheels speed:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD2.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This already saves us a lot of typing –&lt;br /&gt;
But one thing still seems quite laborious: we have to know the exact pin numbers every time we want to change the speed.&lt;br /&gt;
&lt;br /&gt;
Imagine a program in which similar function calls are distributed all over. &lt;br /&gt;
In case of a hardware update you would have to find every single function call and change the parameters manually. &lt;br /&gt;
This effort could surely be spent for more useful things..&lt;br /&gt;
&lt;br /&gt;
It would be ideal to find a way of calling a certain function that only offers the most useful parameters (like setting the speed) and which handles technical details (switching pins on and off) internally.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Possible solution: Data and code in one package – „Classes“ and „Objects“==&lt;br /&gt;
&lt;br /&gt;
C++ (and also Arduino) provides a specific feature that can solve our problem: Classes and Objects&lt;br /&gt;
&lt;br /&gt;
A Class predefines common qualities of a group of Objects. &lt;br /&gt;
It for instance determines that every motor has the possibility to exert a certain amount of throttle. &lt;br /&gt;
The corresponding program could look like this:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD3.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now the computer knows that there is a class called „Motor“.&lt;br /&gt;
This class (class) provides a function called „setThrottle“ that is called as an argument by using a number (int) and that does not return anything (void).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Classes are Data-types===&lt;br /&gt;
&lt;br /&gt;
We can use our „Motor“ - class the same way we are using other data - types (int, long, float).&amp;lt;p&amp;gt;&lt;br /&gt;
The following lines use that quality in order to implement two motors:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD4.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Calling inner functions of a class (Methods)===&lt;br /&gt;
&lt;br /&gt;
Imagine we want to drive the left motor with full throttle whereas the right motor should stop completely. &lt;br /&gt;
This can be expressed as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD5.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A positive side effect: your program gains readability by picking distinct names for your Objects and Methods.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Classes can contain other variables that can only be accessed „internally“===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do the Objects „leftMotor“ and „rightMotor“ know which pins they want to switch on and off?&lt;br /&gt;
&lt;br /&gt;
Until now our „Motor“ class is quite abstract since it does not contain this information. &lt;br /&gt;
A class that should conduct practical actions needs further variables (concrete pin numbers) and lines of code that describe what to do exactly.&lt;br /&gt;
We can simply include both things in the class definition:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD6.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do we include the pin numbers into the Object if they are not visible from the outside?&lt;br /&gt;
We simply write a „setup“ Function for the class:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD7.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==A complete example ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to construct a complete example we only have to include the „speed“-Function (see description above):&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD8.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Organizing classes in separate files==&lt;br /&gt;
&lt;br /&gt;
We can improve our program structure by putting classes in separate files:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:1. &lt;br /&gt;
:Click on the arrow in the right corner in order to add a new file.&lt;br /&gt;
:Select „new Tab“.&lt;br /&gt;
&lt;br /&gt;
:[[File:NewTabARDU.jpg]]&lt;br /&gt;
&lt;br /&gt;
:2.&lt;br /&gt;
:Enter a filename at the bottom of the window. &lt;br /&gt;
:It must end with .h – In our case it could be &#039;motorControl.h&#039;.&lt;br /&gt;
&lt;br /&gt;
:3.&lt;br /&gt;
:The first line of your code should be:&lt;br /&gt;
&lt;br /&gt;
:&#039;#include „Arduino.h“&#039;&lt;br /&gt;
&lt;br /&gt;
:This line &#039;links&#039; the file to the Arduino–specific features.&lt;br /&gt;
:Now we can include the code of our class.&lt;br /&gt;
&lt;br /&gt;
:4.&lt;br /&gt;
:Go back to your main file.&lt;br /&gt;
:Now you have to &#039;link&#039; the new file to your main file in order to use the features of our class.&lt;br /&gt;
:Include the following line in the top of your main file&lt;br /&gt;
&lt;br /&gt;
:&#039;#include &amp;quot;MotorControl.h“&#039;&lt;br /&gt;
&lt;br /&gt;
:and write the rest of your program as usual.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==More details on the concept==&lt;br /&gt;
&lt;br /&gt;
Classes can build up on each other (inheritance)&lt;br /&gt;
&lt;br /&gt;
In the beginning we promised that it is possible to replace different motor drivers without changing the rest of the program.&lt;br /&gt;
Classes can indeed include other Objects in the form of „member variables“.&lt;br /&gt;
&lt;br /&gt;
C++ allows class declarations and the code for included Functions to be be placed in different files. &lt;br /&gt;
If you want to know more about that you can read this article about creating libraries in Arduino: [http://arduino.cc/en/Hacking/LibraryTutorial http://arduino.cc/en/Hacking/LibraryTutorial ]&lt;/div&gt;</summary>
		<author><name>Veja6203</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90141</id>
		<title>GMU:Functions and Classes (Arduino)</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90141"/>
		<updated>2017-03-28T13:44:38Z</updated>

		<summary type="html">&lt;p&gt;Veja6203: /* Organizing classes in separate files */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Motivation==&lt;br /&gt;
&lt;br /&gt;
Soon after starting to write the program for your robot you will encounter some typical problems:&lt;br /&gt;
&lt;br /&gt;
* clarity: the bigger the program gets the harder it is to keep the general overview&lt;br /&gt;
* decoupling: you only want to change a certain part of the program without influencing all the rest&lt;br /&gt;
* recyclability: there are several similar parts in your robot for which you would like to reuse particular sections of your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These problems reach back to the beginning of programming and their solution is an art and a science at the same time.&lt;br /&gt;
It generally helps a lot to separate your program into single subunits that are relatively independent from each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example: Controlling Motors==&lt;br /&gt;
&lt;br /&gt;
The [http://arduino.cc/de/Reference/FunctionDeclaration function] is an enormous useful tool that can help you structuring your code. Functions allow you to sum up several operations under the same command. This command can be called again and again without knowing about or duplicating the included code. &lt;br /&gt;
&lt;br /&gt;
Here is an example for a function for setting the speed of a motor that is connected to an H-bridge:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD1.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now (and for every prospective motor movement) we only need to write one single line in order to for instance setting the left wheels speed:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD2.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This already saves us a lot of typing –&lt;br /&gt;
But one thing still seems quite laborious: we have to know the exact pin numbers every time we want to change the speed.&lt;br /&gt;
&lt;br /&gt;
Imagine a program in which similar function calls are distributed all over. &lt;br /&gt;
In case of a hardware update you would have to find every single function call and change the parameters manually. &lt;br /&gt;
This effort could surely be spent for more useful things..&lt;br /&gt;
&lt;br /&gt;
It would be ideal to find a way of calling a certain function that only offers the most useful parameters (like setting the speed) and which handles technical details (switching pins on and off) internally.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Possible solution: Data and code in one package – „Classes“ and „Objects“==&lt;br /&gt;
&lt;br /&gt;
C++ (and also Arduino) provides a specific feature that can solve our problem: Classes and Objects&lt;br /&gt;
&lt;br /&gt;
A Class predefines common qualities of a group of Objects. &lt;br /&gt;
It for instance determines that every motor has the possibility to exert a certain amount of throttle. &lt;br /&gt;
The corresponding program could look like this:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD3.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now the computer knows that there is a class called „Motor“.&lt;br /&gt;
This class (class) provides a function called „setThrottle“ that is called as an argument by using a number (int) and that does not return anything (void).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Classes are Data-types===&lt;br /&gt;
&lt;br /&gt;
We can use our „Motor“ - class the same way we are using other data - types (int, long, float).&amp;lt;p&amp;gt;&lt;br /&gt;
The following lines use that quality in order to implement two motors:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD4.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Calling inner functions of a class (Methods)===&lt;br /&gt;
&lt;br /&gt;
Imagine we want to drive the left motor with full throttle whereas the right motor should stop completely. &lt;br /&gt;
This can be expressed as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD5.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A positive side effect: your program gains readability by picking distinct names for your Objects and Methods.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Classes can contain other variables that can only be accessed „internally“===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do the Objects „leftMotor“ and „rightMotor“ know which pins they want to switch on and off?&lt;br /&gt;
&lt;br /&gt;
Until now our „Motor“ class is quite abstract since it does not contain this information. &lt;br /&gt;
A class that should conduct practical actions needs further variables (concrete pin numbers) and lines of code that describe what to do exactly.&lt;br /&gt;
We can simply include both things in the class definition:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD6.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do we include the pin numbers into the Object if they are not visible from the outside?&lt;br /&gt;
We simply write a „setup“ Function for the class:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD7.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==A complete example ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to construct a complete example we only have to include the „speed“-Function (see description above):&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD8.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Organizing classes in separate files==&lt;br /&gt;
&lt;br /&gt;
We can improve our program structure by putting classes in separate files:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:1. &lt;br /&gt;
:Click on the arrow in the right corner in order to add a new file.&lt;br /&gt;
:Select „new Tab“.&lt;br /&gt;
&lt;br /&gt;
:[[File:NewTabARDU.jpg]]&lt;br /&gt;
&lt;br /&gt;
:2.&lt;br /&gt;
:Enter a filename at the bottom of the window. &lt;br /&gt;
:It must end with .h – In our case it could be &#039;motorControl.h&#039;.&lt;br /&gt;
&lt;br /&gt;
:3.&lt;br /&gt;
:The first line of your code should be:&lt;br /&gt;
&lt;br /&gt;
:&#039;#include „Arduino.h“&#039;&lt;br /&gt;
&lt;br /&gt;
:This line &#039;links&#039; the file to the Arduino–specific features.&lt;br /&gt;
:Now we can include the code of our class.&lt;br /&gt;
&lt;br /&gt;
:4.&lt;br /&gt;
:Go back to your main file.&lt;br /&gt;
:Now you have to &#039;link&#039; the new file to your main file in order to use the features of our class.&lt;br /&gt;
:Include the following line in the top of your main file&lt;br /&gt;
&lt;br /&gt;
:&#039;#include &amp;quot;MotorControl.h“&#039;&lt;br /&gt;
&lt;br /&gt;
:and write the rest of your program as usual.&lt;br /&gt;
&lt;br /&gt;
==More details on the concept==&lt;br /&gt;
&lt;br /&gt;
Classes can build up on each other (inheritance)&lt;br /&gt;
&lt;br /&gt;
In the beginning we promised that it is possible to replace different motor drivers without changing the rest of the program.&lt;br /&gt;
Classes can indeed include other Objects in the form of „member variables“.&lt;br /&gt;
&lt;br /&gt;
C++ allows class declarations and the code for included Functions to be be placed in different files. &lt;br /&gt;
If you want to know more about that you can read this article about creating libraries in Arduino: [http://arduino.cc/en/Hacking/LibraryTutorial http://arduino.cc/en/Hacking/LibraryTutorial ]&lt;/div&gt;</summary>
		<author><name>Veja6203</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=File:NewTabARDU.jpg&amp;diff=90140</id>
		<title>File:NewTabARDU.jpg</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=File:NewTabARDU.jpg&amp;diff=90140"/>
		<updated>2017-03-28T13:44:35Z</updated>

		<summary type="html">&lt;p&gt;Veja6203: File uploaded with MsUpload&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;File uploaded with MsUpload&lt;/div&gt;</summary>
		<author><name>Veja6203</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90139</id>
		<title>GMU:Functions and Classes (Arduino)</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90139"/>
		<updated>2017-03-28T11:48:12Z</updated>

		<summary type="html">&lt;p&gt;Veja6203: /* A complete example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Motivation==&lt;br /&gt;
&lt;br /&gt;
Soon after starting to write the program for your robot you will encounter some typical problems:&lt;br /&gt;
&lt;br /&gt;
* clarity: the bigger the program gets the harder it is to keep the general overview&lt;br /&gt;
* decoupling: you only want to change a certain part of the program without influencing all the rest&lt;br /&gt;
* recyclability: there are several similar parts in your robot for which you would like to reuse particular sections of your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These problems reach back to the beginning of programming and their solution is an art and a science at the same time.&lt;br /&gt;
It generally helps a lot to separate your program into single subunits that are relatively independent from each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example: Controlling Motors==&lt;br /&gt;
&lt;br /&gt;
The [http://arduino.cc/de/Reference/FunctionDeclaration function] is an enormous useful tool that can help you structuring your code. Functions allow you to sum up several operations under the same command. This command can be called again and again without knowing about or duplicating the included code. &lt;br /&gt;
&lt;br /&gt;
Here is an example for a function for setting the speed of a motor that is connected to an H-bridge:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD1.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now (and for every prospective motor movement) we only need to write one single line in order to for instance setting the left wheels speed:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD2.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This already saves us a lot of typing –&lt;br /&gt;
But one thing still seems quite laborious: we have to know the exact pin numbers every time we want to change the speed.&lt;br /&gt;
&lt;br /&gt;
Imagine a program in which similar function calls are distributed all over. &lt;br /&gt;
In case of a hardware update you would have to find every single function call and change the parameters manually. &lt;br /&gt;
This effort could surely be spent for more useful things..&lt;br /&gt;
&lt;br /&gt;
It would be ideal to find a way of calling a certain function that only offers the most useful parameters (like setting the speed) and which handles technical details (switching pins on and off) internally.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Possible solution: Data and code in one package – „Classes“ and „Objects“==&lt;br /&gt;
&lt;br /&gt;
C++ (and also Arduino) provides a specific feature that can solve our problem: Classes and Objects&lt;br /&gt;
&lt;br /&gt;
A Class predefines common qualities of a group of Objects. &lt;br /&gt;
It for instance determines that every motor has the possibility to exert a certain amount of throttle. &lt;br /&gt;
The corresponding program could look like this:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD3.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now the computer knows that there is a class called „Motor“.&lt;br /&gt;
This class (class) provides a function called „setThrottle“ that is called as an argument by using a number (int) and that does not return anything (void).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Classes are Data-types===&lt;br /&gt;
&lt;br /&gt;
We can use our „Motor“ - class the same way we are using other data - types (int, long, float).&amp;lt;p&amp;gt;&lt;br /&gt;
The following lines use that quality in order to implement two motors:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD4.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Calling inner functions of a class (Methods)===&lt;br /&gt;
&lt;br /&gt;
Imagine we want to drive the left motor with full throttle whereas the right motor should stop completely. &lt;br /&gt;
This can be expressed as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD5.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A positive side effect: your program gains readability by picking distinct names for your Objects and Methods.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Classes can contain other variables that can only be accessed „internally“===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do the Objects „leftMotor“ and „rightMotor“ know which pins they want to switch on and off?&lt;br /&gt;
&lt;br /&gt;
Until now our „Motor“ class is quite abstract since it does not contain this information. &lt;br /&gt;
A class that should conduct practical actions needs further variables (concrete pin numbers) and lines of code that describe what to do exactly.&lt;br /&gt;
We can simply include both things in the class definition:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD6.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do we include the pin numbers into the Object if they are not visible from the outside?&lt;br /&gt;
We simply write a „setup“ Function for the class:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD7.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==A complete example ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to construct a complete example we only have to include the „speed“-Function (see description above):&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD8.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Organizing classes in separate files==&lt;br /&gt;
&lt;br /&gt;
We can improve our program structure by putting classes in separate files.&lt;br /&gt;
&lt;br /&gt;
1)&lt;br /&gt;
Click on the arrow in the right corner in order to add a new file.&lt;br /&gt;
Select „new Tab“.&lt;br /&gt;
&lt;br /&gt;
----BILD----&lt;br /&gt;
&lt;br /&gt;
2) &lt;br /&gt;
Enter a filename at the bottom of the window. &lt;br /&gt;
It must end with .h !&lt;br /&gt;
In our case I suggest the name motorControl.h.&lt;br /&gt;
&lt;br /&gt;
3) &lt;br /&gt;
Enter the first line:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
#include „Arduino.h“&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This line „links“ the file to the Arduino-specific features.&lt;br /&gt;
Now we can include the code of our class.&lt;br /&gt;
&lt;br /&gt;
4)&lt;br /&gt;
Go back to your main file.&lt;br /&gt;
Now you have to „link“ the new file to your main file in order to use the features of our class.&lt;br /&gt;
Include the following line in the top of your main file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
#include „MotorControl.h“&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
and write the rest of your program as usual.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==More details on the concept==&lt;br /&gt;
&lt;br /&gt;
Classes can build up on each other (inheritance)&lt;br /&gt;
&lt;br /&gt;
In the beginning we promised that it is possible to replace different motor drivers without changing the rest of the program.&lt;br /&gt;
Classes can indeed include other Objects in the form of „member variables“.&lt;br /&gt;
&lt;br /&gt;
C++ allows class declarations and the code for included Functions to be be placed in different files. &lt;br /&gt;
If you want to know more about that you can read this article about creating libraries in Arduino: [http://arduino.cc/en/Hacking/LibraryTutorial http://arduino.cc/en/Hacking/LibraryTutorial ]&lt;/div&gt;</summary>
		<author><name>Veja6203</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=File:OOPARD8.jpg&amp;diff=90138</id>
		<title>File:OOPARD8.jpg</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=File:OOPARD8.jpg&amp;diff=90138"/>
		<updated>2017-03-28T11:48:09Z</updated>

		<summary type="html">&lt;p&gt;Veja6203: File uploaded with MsUpload&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;File uploaded with MsUpload&lt;/div&gt;</summary>
		<author><name>Veja6203</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90137</id>
		<title>GMU:Functions and Classes (Arduino)</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90137"/>
		<updated>2017-03-28T11:42:11Z</updated>

		<summary type="html">&lt;p&gt;Veja6203: /* A complete example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Motivation==&lt;br /&gt;
&lt;br /&gt;
Soon after starting to write the program for your robot you will encounter some typical problems:&lt;br /&gt;
&lt;br /&gt;
* clarity: the bigger the program gets the harder it is to keep the general overview&lt;br /&gt;
* decoupling: you only want to change a certain part of the program without influencing all the rest&lt;br /&gt;
* recyclability: there are several similar parts in your robot for which you would like to reuse particular sections of your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These problems reach back to the beginning of programming and their solution is an art and a science at the same time.&lt;br /&gt;
It generally helps a lot to separate your program into single subunits that are relatively independent from each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example: Controlling Motors==&lt;br /&gt;
&lt;br /&gt;
The [http://arduino.cc/de/Reference/FunctionDeclaration function] is an enormous useful tool that can help you structuring your code. Functions allow you to sum up several operations under the same command. This command can be called again and again without knowing about or duplicating the included code. &lt;br /&gt;
&lt;br /&gt;
Here is an example for a function for setting the speed of a motor that is connected to an H-bridge:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD1.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now (and for every prospective motor movement) we only need to write one single line in order to for instance setting the left wheels speed:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD2.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This already saves us a lot of typing –&lt;br /&gt;
But one thing still seems quite laborious: we have to know the exact pin numbers every time we want to change the speed.&lt;br /&gt;
&lt;br /&gt;
Imagine a program in which similar function calls are distributed all over. &lt;br /&gt;
In case of a hardware update you would have to find every single function call and change the parameters manually. &lt;br /&gt;
This effort could surely be spent for more useful things..&lt;br /&gt;
&lt;br /&gt;
It would be ideal to find a way of calling a certain function that only offers the most useful parameters (like setting the speed) and which handles technical details (switching pins on and off) internally.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Possible solution: Data and code in one package – „Classes“ and „Objects“==&lt;br /&gt;
&lt;br /&gt;
C++ (and also Arduino) provides a specific feature that can solve our problem: Classes and Objects&lt;br /&gt;
&lt;br /&gt;
A Class predefines common qualities of a group of Objects. &lt;br /&gt;
It for instance determines that every motor has the possibility to exert a certain amount of throttle. &lt;br /&gt;
The corresponding program could look like this:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD3.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now the computer knows that there is a class called „Motor“.&lt;br /&gt;
This class (class) provides a function called „setThrottle“ that is called as an argument by using a number (int) and that does not return anything (void).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Classes are Data-types===&lt;br /&gt;
&lt;br /&gt;
We can use our „Motor“ - class the same way we are using other data - types (int, long, float).&amp;lt;p&amp;gt;&lt;br /&gt;
The following lines use that quality in order to implement two motors:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD4.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Calling inner functions of a class (Methods)===&lt;br /&gt;
&lt;br /&gt;
Imagine we want to drive the left motor with full throttle whereas the right motor should stop completely. &lt;br /&gt;
This can be expressed as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD5.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A positive side effect: your program gains readability by picking distinct names for your Objects and Methods.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Classes can contain other variables that can only be accessed „internally“===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do the Objects „leftMotor“ and „rightMotor“ know which pins they want to switch on and off?&lt;br /&gt;
&lt;br /&gt;
Until now our „Motor“ class is quite abstract since it does not contain this information. &lt;br /&gt;
A class that should conduct practical actions needs further variables (concrete pin numbers) and lines of code that describe what to do exactly.&lt;br /&gt;
We can simply include both things in the class definition:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD6.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do we include the pin numbers into the Object if they are not visible from the outside?&lt;br /&gt;
We simply write a „setup“ Function for the class:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD7.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==A complete example ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to construct a complete example we only have to include the „speed“-Function (see description above):&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// Defining a class for motor control&lt;br /&gt;
class MotoMamaMotor {&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  private: // the following definitions are only of „internal use“ for the class itself&lt;br /&gt;
    int forwardPin; //Every MotoMamaMotor type Object has its own forwardPin&lt;br /&gt;
    int reversePin;&lt;br /&gt;
    int throttlePin;&lt;br /&gt;
&lt;br /&gt;
  public: // the following qualities and methods are visible from the outside.&lt;br /&gt;
    //  This setup-Function has to be called before using the motor control&lt;br /&gt;
    void setup(int newForwardPin, int newReversePin, int newThrottlePin) {&lt;br /&gt;
      // we remember the pins for future use&lt;br /&gt;
      forwardPin = newForwardPin;&lt;br /&gt;
      reversePin = newReversePin;&lt;br /&gt;
      throttlePin = newThrottlePin;&lt;br /&gt;
      // and at the same time we initialize the outputs !&lt;br /&gt;
      digitalWrite(throttlePin, LOW); //  so that the motors don’t spin directly from the beginning ..&lt;br /&gt;
      pinMode(forwardPin, OUTPUT);&lt;br /&gt;
      pinMode(reversePin, OUTPUT);&lt;br /&gt;
      pinMode(throttlePin, OUTPUT);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    // this Function allows to control the motor speed&lt;br /&gt;
    void setThrottle (int newThrottle) {&lt;br /&gt;
      if (newThrottle &amp;gt; 0) { // should it spin forwards or backwards?&lt;br /&gt;
        // spin forwards&lt;br /&gt;
        digitalWrite(reversePin, LOW);&lt;br /&gt;
        digitalWrite(forwardPin, HIGH);&lt;br /&gt;
      } else {&lt;br /&gt;
        // spin backwards&lt;br /&gt;
        digitalWrite(forwardPin, LOW);&lt;br /&gt;
        digitalWrite(reversePin, HIGH);&lt;br /&gt;
      }&lt;br /&gt;
      // adjust the speed:&lt;br /&gt;
      analogWrite(throttlePin, newThrottle);&lt;br /&gt;
    }&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
// create two separate MotoMamaMotor type Objects (leftMotor, rightMotor). They can be used as normal variables.&lt;br /&gt;
MotoMamaMotor leftMotor;&lt;br /&gt;
MotoMamaMotor rightMotor;&lt;br /&gt;
&lt;br /&gt;
void setup() { // this is our „main“ setup Function&lt;br /&gt;
  leftMotor.setup(3, 4, 5); // assign the pin numbers for each motor in the setup Function: setup(int newForwardPin, int newReversePin, int newThrottlePin)&lt;br /&gt;
  rightMotor.setup(6, 7, 8);&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
void loop() { // this is our „main“ loop Function where concrete actions are executed. For example:&lt;br /&gt;
  // Start backwards, slow down and accelerate forwards&lt;br /&gt;
  for (int i = -255, i &amp;lt;= 255; i++) {&lt;br /&gt;
    leftMotor.setThrottle(i);&lt;br /&gt;
    rightMotor.setThrottle(i);&lt;br /&gt;
  };&lt;br /&gt;
  // Start forwards, slow down and accelerate backwards&lt;br /&gt;
  for (int i = 255, i &amp;gt;= -255; i--) {&lt;br /&gt;
    leftMotor.setThrottle(i);&lt;br /&gt;
    rightMotor.setThrottle(i);&lt;br /&gt;
  };&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
==Organizing classes in separate files==&lt;br /&gt;
&lt;br /&gt;
We can improve our program structure by putting classes in separate files.&lt;br /&gt;
&lt;br /&gt;
1)&lt;br /&gt;
Click on the arrow in the right corner in order to add a new file.&lt;br /&gt;
Select „new Tab“.&lt;br /&gt;
&lt;br /&gt;
----BILD----&lt;br /&gt;
&lt;br /&gt;
2) &lt;br /&gt;
Enter a filename at the bottom of the window. &lt;br /&gt;
It must end with .h !&lt;br /&gt;
In our case I suggest the name motorControl.h.&lt;br /&gt;
&lt;br /&gt;
3) &lt;br /&gt;
Enter the first line:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
#include „Arduino.h“&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This line „links“ the file to the Arduino-specific features.&lt;br /&gt;
Now we can include the code of our class.&lt;br /&gt;
&lt;br /&gt;
4)&lt;br /&gt;
Go back to your main file.&lt;br /&gt;
Now you have to „link“ the new file to your main file in order to use the features of our class.&lt;br /&gt;
Include the following line in the top of your main file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
#include „MotorControl.h“&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
and write the rest of your program as usual.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==More details on the concept==&lt;br /&gt;
&lt;br /&gt;
Classes can build up on each other (inheritance)&lt;br /&gt;
&lt;br /&gt;
In the beginning we promised that it is possible to replace different motor drivers without changing the rest of the program.&lt;br /&gt;
Classes can indeed include other Objects in the form of „member variables“.&lt;br /&gt;
&lt;br /&gt;
C++ allows class declarations and the code for included Functions to be be placed in different files. &lt;br /&gt;
If you want to know more about that you can read this article about creating libraries in Arduino: [http://arduino.cc/en/Hacking/LibraryTutorial http://arduino.cc/en/Hacking/LibraryTutorial ]&lt;/div&gt;</summary>
		<author><name>Veja6203</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90136</id>
		<title>GMU:Functions and Classes (Arduino)</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90136"/>
		<updated>2017-03-28T11:38:49Z</updated>

		<summary type="html">&lt;p&gt;Veja6203: /* Classes can contain other variables that can only be accessed „internally“ */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Motivation==&lt;br /&gt;
&lt;br /&gt;
Soon after starting to write the program for your robot you will encounter some typical problems:&lt;br /&gt;
&lt;br /&gt;
* clarity: the bigger the program gets the harder it is to keep the general overview&lt;br /&gt;
* decoupling: you only want to change a certain part of the program without influencing all the rest&lt;br /&gt;
* recyclability: there are several similar parts in your robot for which you would like to reuse particular sections of your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These problems reach back to the beginning of programming and their solution is an art and a science at the same time.&lt;br /&gt;
It generally helps a lot to separate your program into single subunits that are relatively independent from each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example: Controlling Motors==&lt;br /&gt;
&lt;br /&gt;
The [http://arduino.cc/de/Reference/FunctionDeclaration function] is an enormous useful tool that can help you structuring your code. Functions allow you to sum up several operations under the same command. This command can be called again and again without knowing about or duplicating the included code. &lt;br /&gt;
&lt;br /&gt;
Here is an example for a function for setting the speed of a motor that is connected to an H-bridge:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD1.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now (and for every prospective motor movement) we only need to write one single line in order to for instance setting the left wheels speed:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD2.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This already saves us a lot of typing –&lt;br /&gt;
But one thing still seems quite laborious: we have to know the exact pin numbers every time we want to change the speed.&lt;br /&gt;
&lt;br /&gt;
Imagine a program in which similar function calls are distributed all over. &lt;br /&gt;
In case of a hardware update you would have to find every single function call and change the parameters manually. &lt;br /&gt;
This effort could surely be spent for more useful things..&lt;br /&gt;
&lt;br /&gt;
It would be ideal to find a way of calling a certain function that only offers the most useful parameters (like setting the speed) and which handles technical details (switching pins on and off) internally.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Possible solution: Data and code in one package – „Classes“ and „Objects“==&lt;br /&gt;
&lt;br /&gt;
C++ (and also Arduino) provides a specific feature that can solve our problem: Classes and Objects&lt;br /&gt;
&lt;br /&gt;
A Class predefines common qualities of a group of Objects. &lt;br /&gt;
It for instance determines that every motor has the possibility to exert a certain amount of throttle. &lt;br /&gt;
The corresponding program could look like this:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD3.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now the computer knows that there is a class called „Motor“.&lt;br /&gt;
This class (class) provides a function called „setThrottle“ that is called as an argument by using a number (int) and that does not return anything (void).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Classes are Data-types===&lt;br /&gt;
&lt;br /&gt;
We can use our „Motor“ - class the same way we are using other data - types (int, long, float).&amp;lt;p&amp;gt;&lt;br /&gt;
The following lines use that quality in order to implement two motors:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD4.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Calling inner functions of a class (Methods)===&lt;br /&gt;
&lt;br /&gt;
Imagine we want to drive the left motor with full throttle whereas the right motor should stop completely. &lt;br /&gt;
This can be expressed as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD5.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A positive side effect: your program gains readability by picking distinct names for your Objects and Methods.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Classes can contain other variables that can only be accessed „internally“===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do the Objects „leftMotor“ and „rightMotor“ know which pins they want to switch on and off?&lt;br /&gt;
&lt;br /&gt;
Until now our „Motor“ class is quite abstract since it does not contain this information. &lt;br /&gt;
A class that should conduct practical actions needs further variables (concrete pin numbers) and lines of code that describe what to do exactly.&lt;br /&gt;
We can simply include both things in the class definition:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD6.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do we include the pin numbers into the Object if they are not visible from the outside?&lt;br /&gt;
We simply write a „setup“ Function for the class:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD7.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==A complete example ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to construct a complete example we only have to include the „speed“-Function (see description above):&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
// Defining a class for motor control &lt;br /&gt;
&lt;br /&gt;
class MotoMamaMotor {&lt;br /&gt;
&lt;br /&gt;
private: // the following definitions are only of „internal use“ for the class itself&lt;br /&gt;
int forwardPin; //Every MotoMamaMotor type Object has its own forwardPin&lt;br /&gt;
int reversePin;&lt;br /&gt;
int throttlePin;&lt;br /&gt;
&lt;br /&gt;
public: // the following qualities and methods are visible from the outside.&lt;br /&gt;
//  This setup-Function has to be called before using the motor control&lt;br /&gt;
void setup(int newForwardPin, int newReversePin, int newThrottlePin){&lt;br /&gt;
// we remember the pins for future use          &lt;br /&gt;
forwardPin=newForwardPin;&lt;br /&gt;
reversePin=newReversePin;&lt;br /&gt;
throttlePin=newThrottlePin;&lt;br /&gt;
// and at the same time we initialize the outputs ! &lt;br /&gt;
digitalWrite(throttlePin,LOW); //  so that the motors don’t spin directly from the beginning .. &lt;br /&gt;
pinMode(forwardPin,OUTPUT);&lt;br /&gt;
pinMode(reversePin,OUTPUT);&lt;br /&gt;
pinMode(throttlePin,OUTPUT);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// this Function allows to control the motor speed &lt;br /&gt;
void setThrottle (int newThrottle){&lt;br /&gt;
if (newThrottle&amp;gt;0){ // should it spin forwards or backwards?&lt;br /&gt;
// spin forwards&lt;br /&gt;
digitalWrite(reversePin,LOW);&lt;br /&gt;
digitalWrite(forwardPin,HIGH);&lt;br /&gt;
}else{&lt;br /&gt;
// spin backwards&lt;br /&gt;
digitalWrite(forwardPin,LOW);&lt;br /&gt;
digitalWrite(reversePin,HIGH);&lt;br /&gt;
}&lt;br /&gt;
// adjust the speed:&lt;br /&gt;
analogWrite(throttlePin, newThrottle);&lt;br /&gt;
}&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
// create two separate MotoMamaMotor type Objects (leftMotor, rightMotor). They can be used as normal variables. &lt;br /&gt;
MotoMamaMotor leftMotor;&lt;br /&gt;
MotoMamaMotor rightMotor;&lt;br /&gt;
&lt;br /&gt;
void setup(){  // this is our „main“ setup Function&lt;br /&gt;
leftMotor.setup(3,4,5);  // assign the pin numbers for each motor in the setup Function: setup(int newForwardPin, int newReversePin, int newThrottlePin)&lt;br /&gt;
rightMotor.setup(6,7,8);&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
void loop(){  // this is our „main“ loop Function where concrete actions are executed. For example:&lt;br /&gt;
// Start backwards, slow down and accelerate forwards &lt;br /&gt;
for (int i =-255, i&amp;lt;=255;i++){&lt;br /&gt;
leftMotor.setThrottle(i);&lt;br /&gt;
rightMotor.setThrottle(i);&lt;br /&gt;
};&lt;br /&gt;
// Start forwards, slow down and accelerate backwards&lt;br /&gt;
for (int i =255, i&amp;gt;=-255;i--){&lt;br /&gt;
leftMotor.setThrottle(i);&lt;br /&gt;
rightMotor.setThrottle(i);&lt;br /&gt;
};&lt;br /&gt;
};&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Organizing classes in separate files==&lt;br /&gt;
&lt;br /&gt;
We can improve our program structure by putting classes in separate files.&lt;br /&gt;
&lt;br /&gt;
1)&lt;br /&gt;
Click on the arrow in the right corner in order to add a new file.&lt;br /&gt;
Select „new Tab“.&lt;br /&gt;
&lt;br /&gt;
----BILD----&lt;br /&gt;
&lt;br /&gt;
2) &lt;br /&gt;
Enter a filename at the bottom of the window. &lt;br /&gt;
It must end with .h !&lt;br /&gt;
In our case I suggest the name motorControl.h.&lt;br /&gt;
&lt;br /&gt;
3) &lt;br /&gt;
Enter the first line:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
#include „Arduino.h“&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This line „links“ the file to the Arduino-specific features.&lt;br /&gt;
Now we can include the code of our class.&lt;br /&gt;
&lt;br /&gt;
4)&lt;br /&gt;
Go back to your main file.&lt;br /&gt;
Now you have to „link“ the new file to your main file in order to use the features of our class.&lt;br /&gt;
Include the following line in the top of your main file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
#include „MotorControl.h“&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
and write the rest of your program as usual.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==More details on the concept==&lt;br /&gt;
&lt;br /&gt;
Classes can build up on each other (inheritance)&lt;br /&gt;
&lt;br /&gt;
In the beginning we promised that it is possible to replace different motor drivers without changing the rest of the program.&lt;br /&gt;
Classes can indeed include other Objects in the form of „member variables“.&lt;br /&gt;
&lt;br /&gt;
C++ allows class declarations and the code for included Functions to be be placed in different files. &lt;br /&gt;
If you want to know more about that you can read this article about creating libraries in Arduino: [http://arduino.cc/en/Hacking/LibraryTutorial http://arduino.cc/en/Hacking/LibraryTutorial ]&lt;/div&gt;</summary>
		<author><name>Veja6203</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90135</id>
		<title>GMU:Functions and Classes (Arduino)</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90135"/>
		<updated>2017-03-28T11:38:26Z</updated>

		<summary type="html">&lt;p&gt;Veja6203: /* Classes can contain other variables that can only be accessed „internally“ */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Motivation==&lt;br /&gt;
&lt;br /&gt;
Soon after starting to write the program for your robot you will encounter some typical problems:&lt;br /&gt;
&lt;br /&gt;
* clarity: the bigger the program gets the harder it is to keep the general overview&lt;br /&gt;
* decoupling: you only want to change a certain part of the program without influencing all the rest&lt;br /&gt;
* recyclability: there are several similar parts in your robot for which you would like to reuse particular sections of your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These problems reach back to the beginning of programming and their solution is an art and a science at the same time.&lt;br /&gt;
It generally helps a lot to separate your program into single subunits that are relatively independent from each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example: Controlling Motors==&lt;br /&gt;
&lt;br /&gt;
The [http://arduino.cc/de/Reference/FunctionDeclaration function] is an enormous useful tool that can help you structuring your code. Functions allow you to sum up several operations under the same command. This command can be called again and again without knowing about or duplicating the included code. &lt;br /&gt;
&lt;br /&gt;
Here is an example for a function for setting the speed of a motor that is connected to an H-bridge:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD1.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now (and for every prospective motor movement) we only need to write one single line in order to for instance setting the left wheels speed:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD2.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This already saves us a lot of typing –&lt;br /&gt;
But one thing still seems quite laborious: we have to know the exact pin numbers every time we want to change the speed.&lt;br /&gt;
&lt;br /&gt;
Imagine a program in which similar function calls are distributed all over. &lt;br /&gt;
In case of a hardware update you would have to find every single function call and change the parameters manually. &lt;br /&gt;
This effort could surely be spent for more useful things..&lt;br /&gt;
&lt;br /&gt;
It would be ideal to find a way of calling a certain function that only offers the most useful parameters (like setting the speed) and which handles technical details (switching pins on and off) internally.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Possible solution: Data and code in one package – „Classes“ and „Objects“==&lt;br /&gt;
&lt;br /&gt;
C++ (and also Arduino) provides a specific feature that can solve our problem: Classes and Objects&lt;br /&gt;
&lt;br /&gt;
A Class predefines common qualities of a group of Objects. &lt;br /&gt;
It for instance determines that every motor has the possibility to exert a certain amount of throttle. &lt;br /&gt;
The corresponding program could look like this:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD3.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now the computer knows that there is a class called „Motor“.&lt;br /&gt;
This class (class) provides a function called „setThrottle“ that is called as an argument by using a number (int) and that does not return anything (void).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Classes are Data-types===&lt;br /&gt;
&lt;br /&gt;
We can use our „Motor“ - class the same way we are using other data - types (int, long, float).&amp;lt;p&amp;gt;&lt;br /&gt;
The following lines use that quality in order to implement two motors:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD4.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Calling inner functions of a class (Methods)===&lt;br /&gt;
&lt;br /&gt;
Imagine we want to drive the left motor with full throttle whereas the right motor should stop completely. &lt;br /&gt;
This can be expressed as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD5.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A positive side effect: your program gains readability by picking distinct names for your Objects and Methods.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Classes can contain other variables that can only be accessed „internally“===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do the Objects „leftMotor“ and „rightMotor“ know which pins they want to switch on and off?&lt;br /&gt;
&lt;br /&gt;
Until now our „Motor“ class is quite abstract since it does not contain this information. &lt;br /&gt;
A class that should conduct practical actions needs further variables (concrete pin numbers) and lines of code that describe what to do exactly.&lt;br /&gt;
We can simply include both things in the class definition:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD6.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do we include the pin numbers into the Object if they are not visible from the outside?&lt;br /&gt;
We simply write a „setup“ Function for the class:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD7.jpg]]&lt;br /&gt;
&lt;br /&gt;
==A complete example ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to construct a complete example we only have to include the „speed“-Function (see description above):&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
// Defining a class for motor control &lt;br /&gt;
&lt;br /&gt;
class MotoMamaMotor {&lt;br /&gt;
&lt;br /&gt;
private: // the following definitions are only of „internal use“ for the class itself&lt;br /&gt;
int forwardPin; //Every MotoMamaMotor type Object has its own forwardPin&lt;br /&gt;
int reversePin;&lt;br /&gt;
int throttlePin;&lt;br /&gt;
&lt;br /&gt;
public: // the following qualities and methods are visible from the outside.&lt;br /&gt;
//  This setup-Function has to be called before using the motor control&lt;br /&gt;
void setup(int newForwardPin, int newReversePin, int newThrottlePin){&lt;br /&gt;
// we remember the pins for future use          &lt;br /&gt;
forwardPin=newForwardPin;&lt;br /&gt;
reversePin=newReversePin;&lt;br /&gt;
throttlePin=newThrottlePin;&lt;br /&gt;
// and at the same time we initialize the outputs ! &lt;br /&gt;
digitalWrite(throttlePin,LOW); //  so that the motors don’t spin directly from the beginning .. &lt;br /&gt;
pinMode(forwardPin,OUTPUT);&lt;br /&gt;
pinMode(reversePin,OUTPUT);&lt;br /&gt;
pinMode(throttlePin,OUTPUT);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// this Function allows to control the motor speed &lt;br /&gt;
void setThrottle (int newThrottle){&lt;br /&gt;
if (newThrottle&amp;gt;0){ // should it spin forwards or backwards?&lt;br /&gt;
// spin forwards&lt;br /&gt;
digitalWrite(reversePin,LOW);&lt;br /&gt;
digitalWrite(forwardPin,HIGH);&lt;br /&gt;
}else{&lt;br /&gt;
// spin backwards&lt;br /&gt;
digitalWrite(forwardPin,LOW);&lt;br /&gt;
digitalWrite(reversePin,HIGH);&lt;br /&gt;
}&lt;br /&gt;
// adjust the speed:&lt;br /&gt;
analogWrite(throttlePin, newThrottle);&lt;br /&gt;
}&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
// create two separate MotoMamaMotor type Objects (leftMotor, rightMotor). They can be used as normal variables. &lt;br /&gt;
MotoMamaMotor leftMotor;&lt;br /&gt;
MotoMamaMotor rightMotor;&lt;br /&gt;
&lt;br /&gt;
void setup(){  // this is our „main“ setup Function&lt;br /&gt;
leftMotor.setup(3,4,5);  // assign the pin numbers for each motor in the setup Function: setup(int newForwardPin, int newReversePin, int newThrottlePin)&lt;br /&gt;
rightMotor.setup(6,7,8);&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
void loop(){  // this is our „main“ loop Function where concrete actions are executed. For example:&lt;br /&gt;
// Start backwards, slow down and accelerate forwards &lt;br /&gt;
for (int i =-255, i&amp;lt;=255;i++){&lt;br /&gt;
leftMotor.setThrottle(i);&lt;br /&gt;
rightMotor.setThrottle(i);&lt;br /&gt;
};&lt;br /&gt;
// Start forwards, slow down and accelerate backwards&lt;br /&gt;
for (int i =255, i&amp;gt;=-255;i--){&lt;br /&gt;
leftMotor.setThrottle(i);&lt;br /&gt;
rightMotor.setThrottle(i);&lt;br /&gt;
};&lt;br /&gt;
};&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Organizing classes in separate files==&lt;br /&gt;
&lt;br /&gt;
We can improve our program structure by putting classes in separate files.&lt;br /&gt;
&lt;br /&gt;
1)&lt;br /&gt;
Click on the arrow in the right corner in order to add a new file.&lt;br /&gt;
Select „new Tab“.&lt;br /&gt;
&lt;br /&gt;
----BILD----&lt;br /&gt;
&lt;br /&gt;
2) &lt;br /&gt;
Enter a filename at the bottom of the window. &lt;br /&gt;
It must end with .h !&lt;br /&gt;
In our case I suggest the name motorControl.h.&lt;br /&gt;
&lt;br /&gt;
3) &lt;br /&gt;
Enter the first line:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
#include „Arduino.h“&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This line „links“ the file to the Arduino-specific features.&lt;br /&gt;
Now we can include the code of our class.&lt;br /&gt;
&lt;br /&gt;
4)&lt;br /&gt;
Go back to your main file.&lt;br /&gt;
Now you have to „link“ the new file to your main file in order to use the features of our class.&lt;br /&gt;
Include the following line in the top of your main file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
#include „MotorControl.h“&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
and write the rest of your program as usual.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==More details on the concept==&lt;br /&gt;
&lt;br /&gt;
Classes can build up on each other (inheritance)&lt;br /&gt;
&lt;br /&gt;
In the beginning we promised that it is possible to replace different motor drivers without changing the rest of the program.&lt;br /&gt;
Classes can indeed include other Objects in the form of „member variables“.&lt;br /&gt;
&lt;br /&gt;
C++ allows class declarations and the code for included Functions to be be placed in different files. &lt;br /&gt;
If you want to know more about that you can read this article about creating libraries in Arduino: [http://arduino.cc/en/Hacking/LibraryTutorial http://arduino.cc/en/Hacking/LibraryTutorial ]&lt;/div&gt;</summary>
		<author><name>Veja6203</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=File:OOPARD6.jpg&amp;diff=90134</id>
		<title>File:OOPARD6.jpg</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=File:OOPARD6.jpg&amp;diff=90134"/>
		<updated>2017-03-28T11:38:23Z</updated>

		<summary type="html">&lt;p&gt;Veja6203: Veja6203 uploaded a new version of File:OOPARD6.jpg&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;File uploaded with MsUpload&lt;/div&gt;</summary>
		<author><name>Veja6203</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90133</id>
		<title>GMU:Functions and Classes (Arduino)</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90133"/>
		<updated>2017-03-28T11:37:10Z</updated>

		<summary type="html">&lt;p&gt;Veja6203: /* Classes can contain other variables that can only be accessed „internally“ */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Motivation==&lt;br /&gt;
&lt;br /&gt;
Soon after starting to write the program for your robot you will encounter some typical problems:&lt;br /&gt;
&lt;br /&gt;
* clarity: the bigger the program gets the harder it is to keep the general overview&lt;br /&gt;
* decoupling: you only want to change a certain part of the program without influencing all the rest&lt;br /&gt;
* recyclability: there are several similar parts in your robot for which you would like to reuse particular sections of your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These problems reach back to the beginning of programming and their solution is an art and a science at the same time.&lt;br /&gt;
It generally helps a lot to separate your program into single subunits that are relatively independent from each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example: Controlling Motors==&lt;br /&gt;
&lt;br /&gt;
The [http://arduino.cc/de/Reference/FunctionDeclaration function] is an enormous useful tool that can help you structuring your code. Functions allow you to sum up several operations under the same command. This command can be called again and again without knowing about or duplicating the included code. &lt;br /&gt;
&lt;br /&gt;
Here is an example for a function for setting the speed of a motor that is connected to an H-bridge:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD1.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now (and for every prospective motor movement) we only need to write one single line in order to for instance setting the left wheels speed:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD2.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This already saves us a lot of typing –&lt;br /&gt;
But one thing still seems quite laborious: we have to know the exact pin numbers every time we want to change the speed.&lt;br /&gt;
&lt;br /&gt;
Imagine a program in which similar function calls are distributed all over. &lt;br /&gt;
In case of a hardware update you would have to find every single function call and change the parameters manually. &lt;br /&gt;
This effort could surely be spent for more useful things..&lt;br /&gt;
&lt;br /&gt;
It would be ideal to find a way of calling a certain function that only offers the most useful parameters (like setting the speed) and which handles technical details (switching pins on and off) internally.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Possible solution: Data and code in one package – „Classes“ and „Objects“==&lt;br /&gt;
&lt;br /&gt;
C++ (and also Arduino) provides a specific feature that can solve our problem: Classes and Objects&lt;br /&gt;
&lt;br /&gt;
A Class predefines common qualities of a group of Objects. &lt;br /&gt;
It for instance determines that every motor has the possibility to exert a certain amount of throttle. &lt;br /&gt;
The corresponding program could look like this:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD3.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now the computer knows that there is a class called „Motor“.&lt;br /&gt;
This class (class) provides a function called „setThrottle“ that is called as an argument by using a number (int) and that does not return anything (void).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Classes are Data-types===&lt;br /&gt;
&lt;br /&gt;
We can use our „Motor“ - class the same way we are using other data - types (int, long, float).&amp;lt;p&amp;gt;&lt;br /&gt;
The following lines use that quality in order to implement two motors:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD4.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Calling inner functions of a class (Methods)===&lt;br /&gt;
&lt;br /&gt;
Imagine we want to drive the left motor with full throttle whereas the right motor should stop completely. &lt;br /&gt;
This can be expressed as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD5.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A positive side effect: your program gains readability by picking distinct names for your Objects and Methods.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Classes can contain other variables that can only be accessed „internally“===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do the Objects „leftMotor“ and „rightMotor“ know which pins they want to switch on and off?&lt;br /&gt;
&lt;br /&gt;
Until now our „Motor“ class is quite abstract since it does not contain this information. &lt;br /&gt;
A class that should conduct practical actions needs further variables (concrete pin numbers) and lines of code that describe what to do exactly.&lt;br /&gt;
We can simply include both things in the class definition:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[OOPARD6.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do we include the pin numbers into the Object if they are not visible from the outside?&lt;br /&gt;
We simply write a „setup“ Function for the class:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD7.jpg]]&lt;br /&gt;
&lt;br /&gt;
==A complete example ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to construct a complete example we only have to include the „speed“-Function (see description above):&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
// Defining a class for motor control &lt;br /&gt;
&lt;br /&gt;
class MotoMamaMotor {&lt;br /&gt;
&lt;br /&gt;
private: // the following definitions are only of „internal use“ for the class itself&lt;br /&gt;
int forwardPin; //Every MotoMamaMotor type Object has its own forwardPin&lt;br /&gt;
int reversePin;&lt;br /&gt;
int throttlePin;&lt;br /&gt;
&lt;br /&gt;
public: // the following qualities and methods are visible from the outside.&lt;br /&gt;
//  This setup-Function has to be called before using the motor control&lt;br /&gt;
void setup(int newForwardPin, int newReversePin, int newThrottlePin){&lt;br /&gt;
// we remember the pins for future use          &lt;br /&gt;
forwardPin=newForwardPin;&lt;br /&gt;
reversePin=newReversePin;&lt;br /&gt;
throttlePin=newThrottlePin;&lt;br /&gt;
// and at the same time we initialize the outputs ! &lt;br /&gt;
digitalWrite(throttlePin,LOW); //  so that the motors don’t spin directly from the beginning .. &lt;br /&gt;
pinMode(forwardPin,OUTPUT);&lt;br /&gt;
pinMode(reversePin,OUTPUT);&lt;br /&gt;
pinMode(throttlePin,OUTPUT);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// this Function allows to control the motor speed &lt;br /&gt;
void setThrottle (int newThrottle){&lt;br /&gt;
if (newThrottle&amp;gt;0){ // should it spin forwards or backwards?&lt;br /&gt;
// spin forwards&lt;br /&gt;
digitalWrite(reversePin,LOW);&lt;br /&gt;
digitalWrite(forwardPin,HIGH);&lt;br /&gt;
}else{&lt;br /&gt;
// spin backwards&lt;br /&gt;
digitalWrite(forwardPin,LOW);&lt;br /&gt;
digitalWrite(reversePin,HIGH);&lt;br /&gt;
}&lt;br /&gt;
// adjust the speed:&lt;br /&gt;
analogWrite(throttlePin, newThrottle);&lt;br /&gt;
}&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
// create two separate MotoMamaMotor type Objects (leftMotor, rightMotor). They can be used as normal variables. &lt;br /&gt;
MotoMamaMotor leftMotor;&lt;br /&gt;
MotoMamaMotor rightMotor;&lt;br /&gt;
&lt;br /&gt;
void setup(){  // this is our „main“ setup Function&lt;br /&gt;
leftMotor.setup(3,4,5);  // assign the pin numbers for each motor in the setup Function: setup(int newForwardPin, int newReversePin, int newThrottlePin)&lt;br /&gt;
rightMotor.setup(6,7,8);&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
void loop(){  // this is our „main“ loop Function where concrete actions are executed. For example:&lt;br /&gt;
// Start backwards, slow down and accelerate forwards &lt;br /&gt;
for (int i =-255, i&amp;lt;=255;i++){&lt;br /&gt;
leftMotor.setThrottle(i);&lt;br /&gt;
rightMotor.setThrottle(i);&lt;br /&gt;
};&lt;br /&gt;
// Start forwards, slow down and accelerate backwards&lt;br /&gt;
for (int i =255, i&amp;gt;=-255;i--){&lt;br /&gt;
leftMotor.setThrottle(i);&lt;br /&gt;
rightMotor.setThrottle(i);&lt;br /&gt;
};&lt;br /&gt;
};&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Organizing classes in separate files==&lt;br /&gt;
&lt;br /&gt;
We can improve our program structure by putting classes in separate files.&lt;br /&gt;
&lt;br /&gt;
1)&lt;br /&gt;
Click on the arrow in the right corner in order to add a new file.&lt;br /&gt;
Select „new Tab“.&lt;br /&gt;
&lt;br /&gt;
----BILD----&lt;br /&gt;
&lt;br /&gt;
2) &lt;br /&gt;
Enter a filename at the bottom of the window. &lt;br /&gt;
It must end with .h !&lt;br /&gt;
In our case I suggest the name motorControl.h.&lt;br /&gt;
&lt;br /&gt;
3) &lt;br /&gt;
Enter the first line:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
#include „Arduino.h“&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This line „links“ the file to the Arduino-specific features.&lt;br /&gt;
Now we can include the code of our class.&lt;br /&gt;
&lt;br /&gt;
4)&lt;br /&gt;
Go back to your main file.&lt;br /&gt;
Now you have to „link“ the new file to your main file in order to use the features of our class.&lt;br /&gt;
Include the following line in the top of your main file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
#include „MotorControl.h“&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
and write the rest of your program as usual.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==More details on the concept==&lt;br /&gt;
&lt;br /&gt;
Classes can build up on each other (inheritance)&lt;br /&gt;
&lt;br /&gt;
In the beginning we promised that it is possible to replace different motor drivers without changing the rest of the program.&lt;br /&gt;
Classes can indeed include other Objects in the form of „member variables“.&lt;br /&gt;
&lt;br /&gt;
C++ allows class declarations and the code for included Functions to be be placed in different files. &lt;br /&gt;
If you want to know more about that you can read this article about creating libraries in Arduino: [http://arduino.cc/en/Hacking/LibraryTutorial http://arduino.cc/en/Hacking/LibraryTutorial ]&lt;/div&gt;</summary>
		<author><name>Veja6203</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=File:OOPARD7.jpg&amp;diff=90132</id>
		<title>File:OOPARD7.jpg</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=File:OOPARD7.jpg&amp;diff=90132"/>
		<updated>2017-03-28T11:37:06Z</updated>

		<summary type="html">&lt;p&gt;Veja6203: File uploaded with MsUpload&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;File uploaded with MsUpload&lt;/div&gt;</summary>
		<author><name>Veja6203</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=File:OOPARD6.jpg&amp;diff=90131</id>
		<title>File:OOPARD6.jpg</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=File:OOPARD6.jpg&amp;diff=90131"/>
		<updated>2017-03-28T11:37:03Z</updated>

		<summary type="html">&lt;p&gt;Veja6203: File uploaded with MsUpload&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;File uploaded with MsUpload&lt;/div&gt;</summary>
		<author><name>Veja6203</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90130</id>
		<title>GMU:Functions and Classes (Arduino)</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90130"/>
		<updated>2017-03-28T11:31:46Z</updated>

		<summary type="html">&lt;p&gt;Veja6203: /* Calling inner functions of a class (Methods) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Motivation==&lt;br /&gt;
&lt;br /&gt;
Soon after starting to write the program for your robot you will encounter some typical problems:&lt;br /&gt;
&lt;br /&gt;
* clarity: the bigger the program gets the harder it is to keep the general overview&lt;br /&gt;
* decoupling: you only want to change a certain part of the program without influencing all the rest&lt;br /&gt;
* recyclability: there are several similar parts in your robot for which you would like to reuse particular sections of your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These problems reach back to the beginning of programming and their solution is an art and a science at the same time.&lt;br /&gt;
It generally helps a lot to separate your program into single subunits that are relatively independent from each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example: Controlling Motors==&lt;br /&gt;
&lt;br /&gt;
The [http://arduino.cc/de/Reference/FunctionDeclaration function] is an enormous useful tool that can help you structuring your code. Functions allow you to sum up several operations under the same command. This command can be called again and again without knowing about or duplicating the included code. &lt;br /&gt;
&lt;br /&gt;
Here is an example for a function for setting the speed of a motor that is connected to an H-bridge:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD1.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now (and for every prospective motor movement) we only need to write one single line in order to for instance setting the left wheels speed:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD2.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This already saves us a lot of typing –&lt;br /&gt;
But one thing still seems quite laborious: we have to know the exact pin numbers every time we want to change the speed.&lt;br /&gt;
&lt;br /&gt;
Imagine a program in which similar function calls are distributed all over. &lt;br /&gt;
In case of a hardware update you would have to find every single function call and change the parameters manually. &lt;br /&gt;
This effort could surely be spent for more useful things..&lt;br /&gt;
&lt;br /&gt;
It would be ideal to find a way of calling a certain function that only offers the most useful parameters (like setting the speed) and which handles technical details (switching pins on and off) internally.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Possible solution: Data and code in one package – „Classes“ and „Objects“==&lt;br /&gt;
&lt;br /&gt;
C++ (and also Arduino) provides a specific feature that can solve our problem: Classes and Objects&lt;br /&gt;
&lt;br /&gt;
A Class predefines common qualities of a group of Objects. &lt;br /&gt;
It for instance determines that every motor has the possibility to exert a certain amount of throttle. &lt;br /&gt;
The corresponding program could look like this:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD3.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now the computer knows that there is a class called „Motor“.&lt;br /&gt;
This class (class) provides a function called „setThrottle“ that is called as an argument by using a number (int) and that does not return anything (void).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Classes are Data-types===&lt;br /&gt;
&lt;br /&gt;
We can use our „Motor“ - class the same way we are using other data - types (int, long, float).&amp;lt;p&amp;gt;&lt;br /&gt;
The following lines use that quality in order to implement two motors:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD4.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Calling inner functions of a class (Methods)===&lt;br /&gt;
&lt;br /&gt;
Imagine we want to drive the left motor with full throttle whereas the right motor should stop completely. &lt;br /&gt;
This can be expressed as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD5.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A positive side effect: your program gains readability by picking distinct names for your Objects and Methods.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Classes can contain other variables that can only be accessed „internally“===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do the Objects „leftMotor“ and „rightMotor“ know which pins they want to switch on and off?&lt;br /&gt;
&lt;br /&gt;
Until now our „Motor“ class is quite abstract since it does not contain this information. &lt;br /&gt;
A class that should conduct practical actions needs further variables (concrete pin numbers) and lines of code that describe what to do exactly.&lt;br /&gt;
We can simply include both things in the class definition:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
class MotoMamaMotor {&lt;br /&gt;
...&lt;br /&gt;
private: // the following definitions are only of „internal use“ for the class itself       &lt;br /&gt;
int forwardPin; //  c &lt;br /&gt;
int reversePin;&lt;br /&gt;
int throttlePin;&lt;br /&gt;
...&lt;br /&gt;
};&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do we include the pin numbers into the Object if they are not visible from the outside?&lt;br /&gt;
We simply write a „setup“ Function for the class:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
class MotoMamaMotor {&lt;br /&gt;
private:&lt;br /&gt;
...&lt;br /&gt;
public: //  we want the setup-function to be accessible from the outside.&lt;br /&gt;
void setup (int newForwardPin, int newReversePin, int newThrottlePin){&lt;br /&gt;
// we remember the pins for future use          &lt;br /&gt;
forwardPin=newForwardPin;&lt;br /&gt;
reversePin=newReversePin;&lt;br /&gt;
throttlePin=newThrottlePin;&lt;br /&gt;
// and at the same time we initialize the outputs ! &lt;br /&gt;
digitalWrite(throttlePin,LOW); //  so that the motors don’t spin directly from the beginning .. &lt;br /&gt;
pinMode(forwardPin,OUTPUT);&lt;br /&gt;
pinMode(reversePin,OUTPUT);&lt;br /&gt;
pinMode(throttlePin,OUTPUT);&lt;br /&gt;
}&lt;br /&gt;
...&lt;br /&gt;
};&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==A complete example ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to construct a complete example we only have to include the „speed“-Function (see description above):&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
// Defining a class for motor control &lt;br /&gt;
&lt;br /&gt;
class MotoMamaMotor {&lt;br /&gt;
&lt;br /&gt;
private: // the following definitions are only of „internal use“ for the class itself&lt;br /&gt;
int forwardPin; //Every MotoMamaMotor type Object has its own forwardPin&lt;br /&gt;
int reversePin;&lt;br /&gt;
int throttlePin;&lt;br /&gt;
&lt;br /&gt;
public: // the following qualities and methods are visible from the outside.&lt;br /&gt;
//  This setup-Function has to be called before using the motor control&lt;br /&gt;
void setup(int newForwardPin, int newReversePin, int newThrottlePin){&lt;br /&gt;
// we remember the pins for future use          &lt;br /&gt;
forwardPin=newForwardPin;&lt;br /&gt;
reversePin=newReversePin;&lt;br /&gt;
throttlePin=newThrottlePin;&lt;br /&gt;
// and at the same time we initialize the outputs ! &lt;br /&gt;
digitalWrite(throttlePin,LOW); //  so that the motors don’t spin directly from the beginning .. &lt;br /&gt;
pinMode(forwardPin,OUTPUT);&lt;br /&gt;
pinMode(reversePin,OUTPUT);&lt;br /&gt;
pinMode(throttlePin,OUTPUT);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// this Function allows to control the motor speed &lt;br /&gt;
void setThrottle (int newThrottle){&lt;br /&gt;
if (newThrottle&amp;gt;0){ // should it spin forwards or backwards?&lt;br /&gt;
// spin forwards&lt;br /&gt;
digitalWrite(reversePin,LOW);&lt;br /&gt;
digitalWrite(forwardPin,HIGH);&lt;br /&gt;
}else{&lt;br /&gt;
// spin backwards&lt;br /&gt;
digitalWrite(forwardPin,LOW);&lt;br /&gt;
digitalWrite(reversePin,HIGH);&lt;br /&gt;
}&lt;br /&gt;
// adjust the speed:&lt;br /&gt;
analogWrite(throttlePin, newThrottle);&lt;br /&gt;
}&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
// create two separate MotoMamaMotor type Objects (leftMotor, rightMotor). They can be used as normal variables. &lt;br /&gt;
MotoMamaMotor leftMotor;&lt;br /&gt;
MotoMamaMotor rightMotor;&lt;br /&gt;
&lt;br /&gt;
void setup(){  // this is our „main“ setup Function&lt;br /&gt;
leftMotor.setup(3,4,5);  // assign the pin numbers for each motor in the setup Function: setup(int newForwardPin, int newReversePin, int newThrottlePin)&lt;br /&gt;
rightMotor.setup(6,7,8);&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
void loop(){  // this is our „main“ loop Function where concrete actions are executed. For example:&lt;br /&gt;
// Start backwards, slow down and accelerate forwards &lt;br /&gt;
for (int i =-255, i&amp;lt;=255;i++){&lt;br /&gt;
leftMotor.setThrottle(i);&lt;br /&gt;
rightMotor.setThrottle(i);&lt;br /&gt;
};&lt;br /&gt;
// Start forwards, slow down and accelerate backwards&lt;br /&gt;
for (int i =255, i&amp;gt;=-255;i--){&lt;br /&gt;
leftMotor.setThrottle(i);&lt;br /&gt;
rightMotor.setThrottle(i);&lt;br /&gt;
};&lt;br /&gt;
};&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Organizing classes in separate files==&lt;br /&gt;
&lt;br /&gt;
We can improve our program structure by putting classes in separate files.&lt;br /&gt;
&lt;br /&gt;
1)&lt;br /&gt;
Click on the arrow in the right corner in order to add a new file.&lt;br /&gt;
Select „new Tab“.&lt;br /&gt;
&lt;br /&gt;
----BILD----&lt;br /&gt;
&lt;br /&gt;
2) &lt;br /&gt;
Enter a filename at the bottom of the window. &lt;br /&gt;
It must end with .h !&lt;br /&gt;
In our case I suggest the name motorControl.h.&lt;br /&gt;
&lt;br /&gt;
3) &lt;br /&gt;
Enter the first line:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
#include „Arduino.h“&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This line „links“ the file to the Arduino-specific features.&lt;br /&gt;
Now we can include the code of our class.&lt;br /&gt;
&lt;br /&gt;
4)&lt;br /&gt;
Go back to your main file.&lt;br /&gt;
Now you have to „link“ the new file to your main file in order to use the features of our class.&lt;br /&gt;
Include the following line in the top of your main file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
#include „MotorControl.h“&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
and write the rest of your program as usual.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==More details on the concept==&lt;br /&gt;
&lt;br /&gt;
Classes can build up on each other (inheritance)&lt;br /&gt;
&lt;br /&gt;
In the beginning we promised that it is possible to replace different motor drivers without changing the rest of the program.&lt;br /&gt;
Classes can indeed include other Objects in the form of „member variables“.&lt;br /&gt;
&lt;br /&gt;
C++ allows class declarations and the code for included Functions to be be placed in different files. &lt;br /&gt;
If you want to know more about that you can read this article about creating libraries in Arduino: [http://arduino.cc/en/Hacking/LibraryTutorial http://arduino.cc/en/Hacking/LibraryTutorial ]&lt;/div&gt;</summary>
		<author><name>Veja6203</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90129</id>
		<title>GMU:Functions and Classes (Arduino)</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90129"/>
		<updated>2017-03-28T11:31:27Z</updated>

		<summary type="html">&lt;p&gt;Veja6203: /* Classes are Data-types */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Motivation==&lt;br /&gt;
&lt;br /&gt;
Soon after starting to write the program for your robot you will encounter some typical problems:&lt;br /&gt;
&lt;br /&gt;
* clarity: the bigger the program gets the harder it is to keep the general overview&lt;br /&gt;
* decoupling: you only want to change a certain part of the program without influencing all the rest&lt;br /&gt;
* recyclability: there are several similar parts in your robot for which you would like to reuse particular sections of your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These problems reach back to the beginning of programming and their solution is an art and a science at the same time.&lt;br /&gt;
It generally helps a lot to separate your program into single subunits that are relatively independent from each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example: Controlling Motors==&lt;br /&gt;
&lt;br /&gt;
The [http://arduino.cc/de/Reference/FunctionDeclaration function] is an enormous useful tool that can help you structuring your code. Functions allow you to sum up several operations under the same command. This command can be called again and again without knowing about or duplicating the included code. &lt;br /&gt;
&lt;br /&gt;
Here is an example for a function for setting the speed of a motor that is connected to an H-bridge:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD1.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now (and for every prospective motor movement) we only need to write one single line in order to for instance setting the left wheels speed:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD2.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This already saves us a lot of typing –&lt;br /&gt;
But one thing still seems quite laborious: we have to know the exact pin numbers every time we want to change the speed.&lt;br /&gt;
&lt;br /&gt;
Imagine a program in which similar function calls are distributed all over. &lt;br /&gt;
In case of a hardware update you would have to find every single function call and change the parameters manually. &lt;br /&gt;
This effort could surely be spent for more useful things..&lt;br /&gt;
&lt;br /&gt;
It would be ideal to find a way of calling a certain function that only offers the most useful parameters (like setting the speed) and which handles technical details (switching pins on and off) internally.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Possible solution: Data and code in one package – „Classes“ and „Objects“==&lt;br /&gt;
&lt;br /&gt;
C++ (and also Arduino) provides a specific feature that can solve our problem: Classes and Objects&lt;br /&gt;
&lt;br /&gt;
A Class predefines common qualities of a group of Objects. &lt;br /&gt;
It for instance determines that every motor has the possibility to exert a certain amount of throttle. &lt;br /&gt;
The corresponding program could look like this:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD3.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now the computer knows that there is a class called „Motor“.&lt;br /&gt;
This class (class) provides a function called „setThrottle“ that is called as an argument by using a number (int) and that does not return anything (void).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Classes are Data-types===&lt;br /&gt;
&lt;br /&gt;
We can use our „Motor“ - class the same way we are using other data - types (int, long, float).&amp;lt;p&amp;gt;&lt;br /&gt;
The following lines use that quality in order to implement two motors:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD4.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Calling inner functions of a class (Methods)===&lt;br /&gt;
&lt;br /&gt;
Imagine we want to drive the left motor with full throttle whereas the right motor should stop completely. &lt;br /&gt;
This can be expressed as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD5.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A positive side effect: your program gains readability by picking distinct names for your Objects and Methods.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Classes can contain other variables that can only be accessed „internally“===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do the Objects „leftMotor“ and „rightMotor“ know which pins they want to switch on and off?&lt;br /&gt;
&lt;br /&gt;
Until now our „Motor“ class is quite abstract since it does not contain this information. &lt;br /&gt;
A class that should conduct practical actions needs further variables (concrete pin numbers) and lines of code that describe what to do exactly.&lt;br /&gt;
We can simply include both things in the class definition:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
class MotoMamaMotor {&lt;br /&gt;
...&lt;br /&gt;
private: // the following definitions are only of „internal use“ for the class itself       &lt;br /&gt;
int forwardPin; //  c &lt;br /&gt;
int reversePin;&lt;br /&gt;
int throttlePin;&lt;br /&gt;
...&lt;br /&gt;
};&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do we include the pin numbers into the Object if they are not visible from the outside?&lt;br /&gt;
We simply write a „setup“ Function for the class:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
class MotoMamaMotor {&lt;br /&gt;
private:&lt;br /&gt;
...&lt;br /&gt;
public: //  we want the setup-function to be accessible from the outside.&lt;br /&gt;
void setup (int newForwardPin, int newReversePin, int newThrottlePin){&lt;br /&gt;
// we remember the pins for future use          &lt;br /&gt;
forwardPin=newForwardPin;&lt;br /&gt;
reversePin=newReversePin;&lt;br /&gt;
throttlePin=newThrottlePin;&lt;br /&gt;
// and at the same time we initialize the outputs ! &lt;br /&gt;
digitalWrite(throttlePin,LOW); //  so that the motors don’t spin directly from the beginning .. &lt;br /&gt;
pinMode(forwardPin,OUTPUT);&lt;br /&gt;
pinMode(reversePin,OUTPUT);&lt;br /&gt;
pinMode(throttlePin,OUTPUT);&lt;br /&gt;
}&lt;br /&gt;
...&lt;br /&gt;
};&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==A complete example ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to construct a complete example we only have to include the „speed“-Function (see description above):&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
// Defining a class for motor control &lt;br /&gt;
&lt;br /&gt;
class MotoMamaMotor {&lt;br /&gt;
&lt;br /&gt;
private: // the following definitions are only of „internal use“ for the class itself&lt;br /&gt;
int forwardPin; //Every MotoMamaMotor type Object has its own forwardPin&lt;br /&gt;
int reversePin;&lt;br /&gt;
int throttlePin;&lt;br /&gt;
&lt;br /&gt;
public: // the following qualities and methods are visible from the outside.&lt;br /&gt;
//  This setup-Function has to be called before using the motor control&lt;br /&gt;
void setup(int newForwardPin, int newReversePin, int newThrottlePin){&lt;br /&gt;
// we remember the pins for future use          &lt;br /&gt;
forwardPin=newForwardPin;&lt;br /&gt;
reversePin=newReversePin;&lt;br /&gt;
throttlePin=newThrottlePin;&lt;br /&gt;
// and at the same time we initialize the outputs ! &lt;br /&gt;
digitalWrite(throttlePin,LOW); //  so that the motors don’t spin directly from the beginning .. &lt;br /&gt;
pinMode(forwardPin,OUTPUT);&lt;br /&gt;
pinMode(reversePin,OUTPUT);&lt;br /&gt;
pinMode(throttlePin,OUTPUT);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// this Function allows to control the motor speed &lt;br /&gt;
void setThrottle (int newThrottle){&lt;br /&gt;
if (newThrottle&amp;gt;0){ // should it spin forwards or backwards?&lt;br /&gt;
// spin forwards&lt;br /&gt;
digitalWrite(reversePin,LOW);&lt;br /&gt;
digitalWrite(forwardPin,HIGH);&lt;br /&gt;
}else{&lt;br /&gt;
// spin backwards&lt;br /&gt;
digitalWrite(forwardPin,LOW);&lt;br /&gt;
digitalWrite(reversePin,HIGH);&lt;br /&gt;
}&lt;br /&gt;
// adjust the speed:&lt;br /&gt;
analogWrite(throttlePin, newThrottle);&lt;br /&gt;
}&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
// create two separate MotoMamaMotor type Objects (leftMotor, rightMotor). They can be used as normal variables. &lt;br /&gt;
MotoMamaMotor leftMotor;&lt;br /&gt;
MotoMamaMotor rightMotor;&lt;br /&gt;
&lt;br /&gt;
void setup(){  // this is our „main“ setup Function&lt;br /&gt;
leftMotor.setup(3,4,5);  // assign the pin numbers for each motor in the setup Function: setup(int newForwardPin, int newReversePin, int newThrottlePin)&lt;br /&gt;
rightMotor.setup(6,7,8);&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
void loop(){  // this is our „main“ loop Function where concrete actions are executed. For example:&lt;br /&gt;
// Start backwards, slow down and accelerate forwards &lt;br /&gt;
for (int i =-255, i&amp;lt;=255;i++){&lt;br /&gt;
leftMotor.setThrottle(i);&lt;br /&gt;
rightMotor.setThrottle(i);&lt;br /&gt;
};&lt;br /&gt;
// Start forwards, slow down and accelerate backwards&lt;br /&gt;
for (int i =255, i&amp;gt;=-255;i--){&lt;br /&gt;
leftMotor.setThrottle(i);&lt;br /&gt;
rightMotor.setThrottle(i);&lt;br /&gt;
};&lt;br /&gt;
};&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Organizing classes in separate files==&lt;br /&gt;
&lt;br /&gt;
We can improve our program structure by putting classes in separate files.&lt;br /&gt;
&lt;br /&gt;
1)&lt;br /&gt;
Click on the arrow in the right corner in order to add a new file.&lt;br /&gt;
Select „new Tab“.&lt;br /&gt;
&lt;br /&gt;
----BILD----&lt;br /&gt;
&lt;br /&gt;
2) &lt;br /&gt;
Enter a filename at the bottom of the window. &lt;br /&gt;
It must end with .h !&lt;br /&gt;
In our case I suggest the name motorControl.h.&lt;br /&gt;
&lt;br /&gt;
3) &lt;br /&gt;
Enter the first line:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
#include „Arduino.h“&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This line „links“ the file to the Arduino-specific features.&lt;br /&gt;
Now we can include the code of our class.&lt;br /&gt;
&lt;br /&gt;
4)&lt;br /&gt;
Go back to your main file.&lt;br /&gt;
Now you have to „link“ the new file to your main file in order to use the features of our class.&lt;br /&gt;
Include the following line in the top of your main file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
#include „MotorControl.h“&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
and write the rest of your program as usual.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==More details on the concept==&lt;br /&gt;
&lt;br /&gt;
Classes can build up on each other (inheritance)&lt;br /&gt;
&lt;br /&gt;
In the beginning we promised that it is possible to replace different motor drivers without changing the rest of the program.&lt;br /&gt;
Classes can indeed include other Objects in the form of „member variables“.&lt;br /&gt;
&lt;br /&gt;
C++ allows class declarations and the code for included Functions to be be placed in different files. &lt;br /&gt;
If you want to know more about that you can read this article about creating libraries in Arduino: [http://arduino.cc/en/Hacking/LibraryTutorial http://arduino.cc/en/Hacking/LibraryTutorial ]&lt;/div&gt;</summary>
		<author><name>Veja6203</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90128</id>
		<title>GMU:Functions and Classes (Arduino)</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90128"/>
		<updated>2017-03-28T11:30:48Z</updated>

		<summary type="html">&lt;p&gt;Veja6203: /* Calling inner functions of a class (Methods) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Motivation==&lt;br /&gt;
&lt;br /&gt;
Soon after starting to write the program for your robot you will encounter some typical problems:&lt;br /&gt;
&lt;br /&gt;
* clarity: the bigger the program gets the harder it is to keep the general overview&lt;br /&gt;
* decoupling: you only want to change a certain part of the program without influencing all the rest&lt;br /&gt;
* recyclability: there are several similar parts in your robot for which you would like to reuse particular sections of your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These problems reach back to the beginning of programming and their solution is an art and a science at the same time.&lt;br /&gt;
It generally helps a lot to separate your program into single subunits that are relatively independent from each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example: Controlling Motors==&lt;br /&gt;
&lt;br /&gt;
The [http://arduino.cc/de/Reference/FunctionDeclaration function] is an enormous useful tool that can help you structuring your code. Functions allow you to sum up several operations under the same command. This command can be called again and again without knowing about or duplicating the included code. &lt;br /&gt;
&lt;br /&gt;
Here is an example for a function for setting the speed of a motor that is connected to an H-bridge:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD1.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now (and for every prospective motor movement) we only need to write one single line in order to for instance setting the left wheels speed:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD2.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This already saves us a lot of typing –&lt;br /&gt;
But one thing still seems quite laborious: we have to know the exact pin numbers every time we want to change the speed.&lt;br /&gt;
&lt;br /&gt;
Imagine a program in which similar function calls are distributed all over. &lt;br /&gt;
In case of a hardware update you would have to find every single function call and change the parameters manually. &lt;br /&gt;
This effort could surely be spent for more useful things..&lt;br /&gt;
&lt;br /&gt;
It would be ideal to find a way of calling a certain function that only offers the most useful parameters (like setting the speed) and which handles technical details (switching pins on and off) internally.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Possible solution: Data and code in one package – „Classes“ and „Objects“==&lt;br /&gt;
&lt;br /&gt;
C++ (and also Arduino) provides a specific feature that can solve our problem: Classes and Objects&lt;br /&gt;
&lt;br /&gt;
A Class predefines common qualities of a group of Objects. &lt;br /&gt;
It for instance determines that every motor has the possibility to exert a certain amount of throttle. &lt;br /&gt;
The corresponding program could look like this:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD3.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now the computer knows that there is a class called „Motor“.&lt;br /&gt;
This class (class) provides a function called „setThrottle“ that is called as an argument by using a number (int) and that does not return anything (void).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Classes are Data-types===&lt;br /&gt;
&lt;br /&gt;
We can use our „Motor“ - class the same way we are using other data - types (int, long, float).&amp;lt;p&amp;gt;&lt;br /&gt;
The following lines use that quality in order to implement two motors:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD4.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Calling inner functions of a class (Methods)===&lt;br /&gt;
&lt;br /&gt;
Imagine we want to drive the left motor with full throttle whereas the right motor should stop completely. &lt;br /&gt;
This can be expressed as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD5.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A positive side effect: your program gains readability by picking distinct names for your Objects and Methods.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Classes can contain other variables that can only be accessed „internally“===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do the Objects „leftMotor“ and „rightMotor“ know which pins they want to switch on and off?&lt;br /&gt;
&lt;br /&gt;
Until now our „Motor“ class is quite abstract since it does not contain this information. &lt;br /&gt;
A class that should conduct practical actions needs further variables (concrete pin numbers) and lines of code that describe what to do exactly.&lt;br /&gt;
We can simply include both things in the class definition:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
class MotoMamaMotor {&lt;br /&gt;
...&lt;br /&gt;
private: // the following definitions are only of „internal use“ for the class itself       &lt;br /&gt;
int forwardPin; //  c &lt;br /&gt;
int reversePin;&lt;br /&gt;
int throttlePin;&lt;br /&gt;
...&lt;br /&gt;
};&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do we include the pin numbers into the Object if they are not visible from the outside?&lt;br /&gt;
We simply write a „setup“ Function for the class:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
class MotoMamaMotor {&lt;br /&gt;
private:&lt;br /&gt;
...&lt;br /&gt;
public: //  we want the setup-function to be accessible from the outside.&lt;br /&gt;
void setup (int newForwardPin, int newReversePin, int newThrottlePin){&lt;br /&gt;
// we remember the pins for future use          &lt;br /&gt;
forwardPin=newForwardPin;&lt;br /&gt;
reversePin=newReversePin;&lt;br /&gt;
throttlePin=newThrottlePin;&lt;br /&gt;
// and at the same time we initialize the outputs ! &lt;br /&gt;
digitalWrite(throttlePin,LOW); //  so that the motors don’t spin directly from the beginning .. &lt;br /&gt;
pinMode(forwardPin,OUTPUT);&lt;br /&gt;
pinMode(reversePin,OUTPUT);&lt;br /&gt;
pinMode(throttlePin,OUTPUT);&lt;br /&gt;
}&lt;br /&gt;
...&lt;br /&gt;
};&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==A complete example ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to construct a complete example we only have to include the „speed“-Function (see description above):&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
// Defining a class for motor control &lt;br /&gt;
&lt;br /&gt;
class MotoMamaMotor {&lt;br /&gt;
&lt;br /&gt;
private: // the following definitions are only of „internal use“ for the class itself&lt;br /&gt;
int forwardPin; //Every MotoMamaMotor type Object has its own forwardPin&lt;br /&gt;
int reversePin;&lt;br /&gt;
int throttlePin;&lt;br /&gt;
&lt;br /&gt;
public: // the following qualities and methods are visible from the outside.&lt;br /&gt;
//  This setup-Function has to be called before using the motor control&lt;br /&gt;
void setup(int newForwardPin, int newReversePin, int newThrottlePin){&lt;br /&gt;
// we remember the pins for future use          &lt;br /&gt;
forwardPin=newForwardPin;&lt;br /&gt;
reversePin=newReversePin;&lt;br /&gt;
throttlePin=newThrottlePin;&lt;br /&gt;
// and at the same time we initialize the outputs ! &lt;br /&gt;
digitalWrite(throttlePin,LOW); //  so that the motors don’t spin directly from the beginning .. &lt;br /&gt;
pinMode(forwardPin,OUTPUT);&lt;br /&gt;
pinMode(reversePin,OUTPUT);&lt;br /&gt;
pinMode(throttlePin,OUTPUT);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// this Function allows to control the motor speed &lt;br /&gt;
void setThrottle (int newThrottle){&lt;br /&gt;
if (newThrottle&amp;gt;0){ // should it spin forwards or backwards?&lt;br /&gt;
// spin forwards&lt;br /&gt;
digitalWrite(reversePin,LOW);&lt;br /&gt;
digitalWrite(forwardPin,HIGH);&lt;br /&gt;
}else{&lt;br /&gt;
// spin backwards&lt;br /&gt;
digitalWrite(forwardPin,LOW);&lt;br /&gt;
digitalWrite(reversePin,HIGH);&lt;br /&gt;
}&lt;br /&gt;
// adjust the speed:&lt;br /&gt;
analogWrite(throttlePin, newThrottle);&lt;br /&gt;
}&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
// create two separate MotoMamaMotor type Objects (leftMotor, rightMotor). They can be used as normal variables. &lt;br /&gt;
MotoMamaMotor leftMotor;&lt;br /&gt;
MotoMamaMotor rightMotor;&lt;br /&gt;
&lt;br /&gt;
void setup(){  // this is our „main“ setup Function&lt;br /&gt;
leftMotor.setup(3,4,5);  // assign the pin numbers for each motor in the setup Function: setup(int newForwardPin, int newReversePin, int newThrottlePin)&lt;br /&gt;
rightMotor.setup(6,7,8);&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
void loop(){  // this is our „main“ loop Function where concrete actions are executed. For example:&lt;br /&gt;
// Start backwards, slow down and accelerate forwards &lt;br /&gt;
for (int i =-255, i&amp;lt;=255;i++){&lt;br /&gt;
leftMotor.setThrottle(i);&lt;br /&gt;
rightMotor.setThrottle(i);&lt;br /&gt;
};&lt;br /&gt;
// Start forwards, slow down and accelerate backwards&lt;br /&gt;
for (int i =255, i&amp;gt;=-255;i--){&lt;br /&gt;
leftMotor.setThrottle(i);&lt;br /&gt;
rightMotor.setThrottle(i);&lt;br /&gt;
};&lt;br /&gt;
};&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Organizing classes in separate files==&lt;br /&gt;
&lt;br /&gt;
We can improve our program structure by putting classes in separate files.&lt;br /&gt;
&lt;br /&gt;
1)&lt;br /&gt;
Click on the arrow in the right corner in order to add a new file.&lt;br /&gt;
Select „new Tab“.&lt;br /&gt;
&lt;br /&gt;
----BILD----&lt;br /&gt;
&lt;br /&gt;
2) &lt;br /&gt;
Enter a filename at the bottom of the window. &lt;br /&gt;
It must end with .h !&lt;br /&gt;
In our case I suggest the name motorControl.h.&lt;br /&gt;
&lt;br /&gt;
3) &lt;br /&gt;
Enter the first line:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
#include „Arduino.h“&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This line „links“ the file to the Arduino-specific features.&lt;br /&gt;
Now we can include the code of our class.&lt;br /&gt;
&lt;br /&gt;
4)&lt;br /&gt;
Go back to your main file.&lt;br /&gt;
Now you have to „link“ the new file to your main file in order to use the features of our class.&lt;br /&gt;
Include the following line in the top of your main file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
#include „MotorControl.h“&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
and write the rest of your program as usual.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==More details on the concept==&lt;br /&gt;
&lt;br /&gt;
Classes can build up on each other (inheritance)&lt;br /&gt;
&lt;br /&gt;
In the beginning we promised that it is possible to replace different motor drivers without changing the rest of the program.&lt;br /&gt;
Classes can indeed include other Objects in the form of „member variables“.&lt;br /&gt;
&lt;br /&gt;
C++ allows class declarations and the code for included Functions to be be placed in different files. &lt;br /&gt;
If you want to know more about that you can read this article about creating libraries in Arduino: [http://arduino.cc/en/Hacking/LibraryTutorial http://arduino.cc/en/Hacking/LibraryTutorial ]&lt;/div&gt;</summary>
		<author><name>Veja6203</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=File:OOPARD5.jpg&amp;diff=90127</id>
		<title>File:OOPARD5.jpg</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=File:OOPARD5.jpg&amp;diff=90127"/>
		<updated>2017-03-28T11:30:31Z</updated>

		<summary type="html">&lt;p&gt;Veja6203: File uploaded with MsUpload&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;File uploaded with MsUpload&lt;/div&gt;</summary>
		<author><name>Veja6203</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90126</id>
		<title>GMU:Functions and Classes (Arduino)</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90126"/>
		<updated>2017-03-28T11:28:19Z</updated>

		<summary type="html">&lt;p&gt;Veja6203: /* Classes are Data-types */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Motivation==&lt;br /&gt;
&lt;br /&gt;
Soon after starting to write the program for your robot you will encounter some typical problems:&lt;br /&gt;
&lt;br /&gt;
* clarity: the bigger the program gets the harder it is to keep the general overview&lt;br /&gt;
* decoupling: you only want to change a certain part of the program without influencing all the rest&lt;br /&gt;
* recyclability: there are several similar parts in your robot for which you would like to reuse particular sections of your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These problems reach back to the beginning of programming and their solution is an art and a science at the same time.&lt;br /&gt;
It generally helps a lot to separate your program into single subunits that are relatively independent from each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example: Controlling Motors==&lt;br /&gt;
&lt;br /&gt;
The [http://arduino.cc/de/Reference/FunctionDeclaration function] is an enormous useful tool that can help you structuring your code. Functions allow you to sum up several operations under the same command. This command can be called again and again without knowing about or duplicating the included code. &lt;br /&gt;
&lt;br /&gt;
Here is an example for a function for setting the speed of a motor that is connected to an H-bridge:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD1.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now (and for every prospective motor movement) we only need to write one single line in order to for instance setting the left wheels speed:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD2.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This already saves us a lot of typing –&lt;br /&gt;
But one thing still seems quite laborious: we have to know the exact pin numbers every time we want to change the speed.&lt;br /&gt;
&lt;br /&gt;
Imagine a program in which similar function calls are distributed all over. &lt;br /&gt;
In case of a hardware update you would have to find every single function call and change the parameters manually. &lt;br /&gt;
This effort could surely be spent for more useful things..&lt;br /&gt;
&lt;br /&gt;
It would be ideal to find a way of calling a certain function that only offers the most useful parameters (like setting the speed) and which handles technical details (switching pins on and off) internally.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Possible solution: Data and code in one package – „Classes“ and „Objects“==&lt;br /&gt;
&lt;br /&gt;
C++ (and also Arduino) provides a specific feature that can solve our problem: Classes and Objects&lt;br /&gt;
&lt;br /&gt;
A Class predefines common qualities of a group of Objects. &lt;br /&gt;
It for instance determines that every motor has the possibility to exert a certain amount of throttle. &lt;br /&gt;
The corresponding program could look like this:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD3.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now the computer knows that there is a class called „Motor“.&lt;br /&gt;
This class (class) provides a function called „setThrottle“ that is called as an argument by using a number (int) and that does not return anything (void).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Classes are Data-types===&lt;br /&gt;
&lt;br /&gt;
We can use our „Motor“ - class the same way we are using other data - types (int, long, float).&amp;lt;p&amp;gt;&lt;br /&gt;
The following lines use that quality in order to implement two motors:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD4.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Calling inner functions of a class (Methods)===&lt;br /&gt;
&lt;br /&gt;
Imagine we want to drive the left motor with full throttle whereas the right motor should stop completely. &lt;br /&gt;
This can be expressed as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;// the objetcs name „leftMotor“ and the herein implemented function „setThrottle“ are separated by a dot.&lt;br /&gt;
leftMotor.setThrottle(255);&lt;br /&gt;
rightMotor.setThrottle(0);&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A positive side effect: your program gains readability by picking distinct names for your Objects and Methods.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Classes can contain other variables that can only be accessed „internally“===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do the Objects „leftMotor“ and „rightMotor“ know which pins they want to switch on and off?&lt;br /&gt;
&lt;br /&gt;
Until now our „Motor“ class is quite abstract since it does not contain this information. &lt;br /&gt;
A class that should conduct practical actions needs further variables (concrete pin numbers) and lines of code that describe what to do exactly.&lt;br /&gt;
We can simply include both things in the class definition:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
class MotoMamaMotor {&lt;br /&gt;
...&lt;br /&gt;
private: // the following definitions are only of „internal use“ for the class itself       &lt;br /&gt;
int forwardPin; //  c &lt;br /&gt;
int reversePin;&lt;br /&gt;
int throttlePin;&lt;br /&gt;
...&lt;br /&gt;
};&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do we include the pin numbers into the Object if they are not visible from the outside?&lt;br /&gt;
We simply write a „setup“ Function for the class:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
class MotoMamaMotor {&lt;br /&gt;
private:&lt;br /&gt;
...&lt;br /&gt;
public: //  we want the setup-function to be accessible from the outside.&lt;br /&gt;
void setup (int newForwardPin, int newReversePin, int newThrottlePin){&lt;br /&gt;
// we remember the pins for future use          &lt;br /&gt;
forwardPin=newForwardPin;&lt;br /&gt;
reversePin=newReversePin;&lt;br /&gt;
throttlePin=newThrottlePin;&lt;br /&gt;
// and at the same time we initialize the outputs ! &lt;br /&gt;
digitalWrite(throttlePin,LOW); //  so that the motors don’t spin directly from the beginning .. &lt;br /&gt;
pinMode(forwardPin,OUTPUT);&lt;br /&gt;
pinMode(reversePin,OUTPUT);&lt;br /&gt;
pinMode(throttlePin,OUTPUT);&lt;br /&gt;
}&lt;br /&gt;
...&lt;br /&gt;
};&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==A complete example ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to construct a complete example we only have to include the „speed“-Function (see description above):&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
// Defining a class for motor control &lt;br /&gt;
&lt;br /&gt;
class MotoMamaMotor {&lt;br /&gt;
&lt;br /&gt;
private: // the following definitions are only of „internal use“ for the class itself&lt;br /&gt;
int forwardPin; //Every MotoMamaMotor type Object has its own forwardPin&lt;br /&gt;
int reversePin;&lt;br /&gt;
int throttlePin;&lt;br /&gt;
&lt;br /&gt;
public: // the following qualities and methods are visible from the outside.&lt;br /&gt;
//  This setup-Function has to be called before using the motor control&lt;br /&gt;
void setup(int newForwardPin, int newReversePin, int newThrottlePin){&lt;br /&gt;
// we remember the pins for future use          &lt;br /&gt;
forwardPin=newForwardPin;&lt;br /&gt;
reversePin=newReversePin;&lt;br /&gt;
throttlePin=newThrottlePin;&lt;br /&gt;
// and at the same time we initialize the outputs ! &lt;br /&gt;
digitalWrite(throttlePin,LOW); //  so that the motors don’t spin directly from the beginning .. &lt;br /&gt;
pinMode(forwardPin,OUTPUT);&lt;br /&gt;
pinMode(reversePin,OUTPUT);&lt;br /&gt;
pinMode(throttlePin,OUTPUT);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// this Function allows to control the motor speed &lt;br /&gt;
void setThrottle (int newThrottle){&lt;br /&gt;
if (newThrottle&amp;gt;0){ // should it spin forwards or backwards?&lt;br /&gt;
// spin forwards&lt;br /&gt;
digitalWrite(reversePin,LOW);&lt;br /&gt;
digitalWrite(forwardPin,HIGH);&lt;br /&gt;
}else{&lt;br /&gt;
// spin backwards&lt;br /&gt;
digitalWrite(forwardPin,LOW);&lt;br /&gt;
digitalWrite(reversePin,HIGH);&lt;br /&gt;
}&lt;br /&gt;
// adjust the speed:&lt;br /&gt;
analogWrite(throttlePin, newThrottle);&lt;br /&gt;
}&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
// create two separate MotoMamaMotor type Objects (leftMotor, rightMotor). They can be used as normal variables. &lt;br /&gt;
MotoMamaMotor leftMotor;&lt;br /&gt;
MotoMamaMotor rightMotor;&lt;br /&gt;
&lt;br /&gt;
void setup(){  // this is our „main“ setup Function&lt;br /&gt;
leftMotor.setup(3,4,5);  // assign the pin numbers for each motor in the setup Function: setup(int newForwardPin, int newReversePin, int newThrottlePin)&lt;br /&gt;
rightMotor.setup(6,7,8);&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
void loop(){  // this is our „main“ loop Function where concrete actions are executed. For example:&lt;br /&gt;
// Start backwards, slow down and accelerate forwards &lt;br /&gt;
for (int i =-255, i&amp;lt;=255;i++){&lt;br /&gt;
leftMotor.setThrottle(i);&lt;br /&gt;
rightMotor.setThrottle(i);&lt;br /&gt;
};&lt;br /&gt;
// Start forwards, slow down and accelerate backwards&lt;br /&gt;
for (int i =255, i&amp;gt;=-255;i--){&lt;br /&gt;
leftMotor.setThrottle(i);&lt;br /&gt;
rightMotor.setThrottle(i);&lt;br /&gt;
};&lt;br /&gt;
};&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Organizing classes in separate files==&lt;br /&gt;
&lt;br /&gt;
We can improve our program structure by putting classes in separate files.&lt;br /&gt;
&lt;br /&gt;
1)&lt;br /&gt;
Click on the arrow in the right corner in order to add a new file.&lt;br /&gt;
Select „new Tab“.&lt;br /&gt;
&lt;br /&gt;
----BILD----&lt;br /&gt;
&lt;br /&gt;
2) &lt;br /&gt;
Enter a filename at the bottom of the window. &lt;br /&gt;
It must end with .h !&lt;br /&gt;
In our case I suggest the name motorControl.h.&lt;br /&gt;
&lt;br /&gt;
3) &lt;br /&gt;
Enter the first line:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
#include „Arduino.h“&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This line „links“ the file to the Arduino-specific features.&lt;br /&gt;
Now we can include the code of our class.&lt;br /&gt;
&lt;br /&gt;
4)&lt;br /&gt;
Go back to your main file.&lt;br /&gt;
Now you have to „link“ the new file to your main file in order to use the features of our class.&lt;br /&gt;
Include the following line in the top of your main file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
#include „MotorControl.h“&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
and write the rest of your program as usual.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==More details on the concept==&lt;br /&gt;
&lt;br /&gt;
Classes can build up on each other (inheritance)&lt;br /&gt;
&lt;br /&gt;
In the beginning we promised that it is possible to replace different motor drivers without changing the rest of the program.&lt;br /&gt;
Classes can indeed include other Objects in the form of „member variables“.&lt;br /&gt;
&lt;br /&gt;
C++ allows class declarations and the code for included Functions to be be placed in different files. &lt;br /&gt;
If you want to know more about that you can read this article about creating libraries in Arduino: [http://arduino.cc/en/Hacking/LibraryTutorial http://arduino.cc/en/Hacking/LibraryTutorial ]&lt;/div&gt;</summary>
		<author><name>Veja6203</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90125</id>
		<title>GMU:Functions and Classes (Arduino)</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90125"/>
		<updated>2017-03-28T11:28:00Z</updated>

		<summary type="html">&lt;p&gt;Veja6203: /* Classes are Data-types */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Motivation==&lt;br /&gt;
&lt;br /&gt;
Soon after starting to write the program for your robot you will encounter some typical problems:&lt;br /&gt;
&lt;br /&gt;
* clarity: the bigger the program gets the harder it is to keep the general overview&lt;br /&gt;
* decoupling: you only want to change a certain part of the program without influencing all the rest&lt;br /&gt;
* recyclability: there are several similar parts in your robot for which you would like to reuse particular sections of your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These problems reach back to the beginning of programming and their solution is an art and a science at the same time.&lt;br /&gt;
It generally helps a lot to separate your program into single subunits that are relatively independent from each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example: Controlling Motors==&lt;br /&gt;
&lt;br /&gt;
The [http://arduino.cc/de/Reference/FunctionDeclaration function] is an enormous useful tool that can help you structuring your code. Functions allow you to sum up several operations under the same command. This command can be called again and again without knowing about or duplicating the included code. &lt;br /&gt;
&lt;br /&gt;
Here is an example for a function for setting the speed of a motor that is connected to an H-bridge:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD1.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now (and for every prospective motor movement) we only need to write one single line in order to for instance setting the left wheels speed:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD2.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This already saves us a lot of typing –&lt;br /&gt;
But one thing still seems quite laborious: we have to know the exact pin numbers every time we want to change the speed.&lt;br /&gt;
&lt;br /&gt;
Imagine a program in which similar function calls are distributed all over. &lt;br /&gt;
In case of a hardware update you would have to find every single function call and change the parameters manually. &lt;br /&gt;
This effort could surely be spent for more useful things..&lt;br /&gt;
&lt;br /&gt;
It would be ideal to find a way of calling a certain function that only offers the most useful parameters (like setting the speed) and which handles technical details (switching pins on and off) internally.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Possible solution: Data and code in one package – „Classes“ and „Objects“==&lt;br /&gt;
&lt;br /&gt;
C++ (and also Arduino) provides a specific feature that can solve our problem: Classes and Objects&lt;br /&gt;
&lt;br /&gt;
A Class predefines common qualities of a group of Objects. &lt;br /&gt;
It for instance determines that every motor has the possibility to exert a certain amount of throttle. &lt;br /&gt;
The corresponding program could look like this:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD3.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now the computer knows that there is a class called „Motor“.&lt;br /&gt;
This class (class) provides a function called „setThrottle“ that is called as an argument by using a number (int) and that does not return anything (void).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Classes are Data-types===&lt;br /&gt;
&lt;br /&gt;
We can use our „Motor“ - class the same way we are using other data - types (int, long, float).&amp;lt;p&amp;gt;&lt;br /&gt;
The following lines use that quality in order to implement two motors:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD4.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Calling inner functions of a class (Methods)===&lt;br /&gt;
&lt;br /&gt;
Imagine we want to drive the left motor with full throttle whereas the right motor should stop completely. &lt;br /&gt;
This can be expressed as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;// the objetcs name „leftMotor“ and the herein implemented function „setThrottle“ are separated by a dot.&lt;br /&gt;
leftMotor.setThrottle(255);&lt;br /&gt;
rightMotor.setThrottle(0);&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A positive side effect: your program gains readability by picking distinct names for your Objects and Methods.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Classes can contain other variables that can only be accessed „internally“===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do the Objects „leftMotor“ and „rightMotor“ know which pins they want to switch on and off?&lt;br /&gt;
&lt;br /&gt;
Until now our „Motor“ class is quite abstract since it does not contain this information. &lt;br /&gt;
A class that should conduct practical actions needs further variables (concrete pin numbers) and lines of code that describe what to do exactly.&lt;br /&gt;
We can simply include both things in the class definition:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
class MotoMamaMotor {&lt;br /&gt;
...&lt;br /&gt;
private: // the following definitions are only of „internal use“ for the class itself       &lt;br /&gt;
int forwardPin; //  c &lt;br /&gt;
int reversePin;&lt;br /&gt;
int throttlePin;&lt;br /&gt;
...&lt;br /&gt;
};&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do we include the pin numbers into the Object if they are not visible from the outside?&lt;br /&gt;
We simply write a „setup“ Function for the class:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
class MotoMamaMotor {&lt;br /&gt;
private:&lt;br /&gt;
...&lt;br /&gt;
public: //  we want the setup-function to be accessible from the outside.&lt;br /&gt;
void setup (int newForwardPin, int newReversePin, int newThrottlePin){&lt;br /&gt;
// we remember the pins for future use          &lt;br /&gt;
forwardPin=newForwardPin;&lt;br /&gt;
reversePin=newReversePin;&lt;br /&gt;
throttlePin=newThrottlePin;&lt;br /&gt;
// and at the same time we initialize the outputs ! &lt;br /&gt;
digitalWrite(throttlePin,LOW); //  so that the motors don’t spin directly from the beginning .. &lt;br /&gt;
pinMode(forwardPin,OUTPUT);&lt;br /&gt;
pinMode(reversePin,OUTPUT);&lt;br /&gt;
pinMode(throttlePin,OUTPUT);&lt;br /&gt;
}&lt;br /&gt;
...&lt;br /&gt;
};&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==A complete example ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to construct a complete example we only have to include the „speed“-Function (see description above):&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
// Defining a class for motor control &lt;br /&gt;
&lt;br /&gt;
class MotoMamaMotor {&lt;br /&gt;
&lt;br /&gt;
private: // the following definitions are only of „internal use“ for the class itself&lt;br /&gt;
int forwardPin; //Every MotoMamaMotor type Object has its own forwardPin&lt;br /&gt;
int reversePin;&lt;br /&gt;
int throttlePin;&lt;br /&gt;
&lt;br /&gt;
public: // the following qualities and methods are visible from the outside.&lt;br /&gt;
//  This setup-Function has to be called before using the motor control&lt;br /&gt;
void setup(int newForwardPin, int newReversePin, int newThrottlePin){&lt;br /&gt;
// we remember the pins for future use          &lt;br /&gt;
forwardPin=newForwardPin;&lt;br /&gt;
reversePin=newReversePin;&lt;br /&gt;
throttlePin=newThrottlePin;&lt;br /&gt;
// and at the same time we initialize the outputs ! &lt;br /&gt;
digitalWrite(throttlePin,LOW); //  so that the motors don’t spin directly from the beginning .. &lt;br /&gt;
pinMode(forwardPin,OUTPUT);&lt;br /&gt;
pinMode(reversePin,OUTPUT);&lt;br /&gt;
pinMode(throttlePin,OUTPUT);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// this Function allows to control the motor speed &lt;br /&gt;
void setThrottle (int newThrottle){&lt;br /&gt;
if (newThrottle&amp;gt;0){ // should it spin forwards or backwards?&lt;br /&gt;
// spin forwards&lt;br /&gt;
digitalWrite(reversePin,LOW);&lt;br /&gt;
digitalWrite(forwardPin,HIGH);&lt;br /&gt;
}else{&lt;br /&gt;
// spin backwards&lt;br /&gt;
digitalWrite(forwardPin,LOW);&lt;br /&gt;
digitalWrite(reversePin,HIGH);&lt;br /&gt;
}&lt;br /&gt;
// adjust the speed:&lt;br /&gt;
analogWrite(throttlePin, newThrottle);&lt;br /&gt;
}&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
// create two separate MotoMamaMotor type Objects (leftMotor, rightMotor). They can be used as normal variables. &lt;br /&gt;
MotoMamaMotor leftMotor;&lt;br /&gt;
MotoMamaMotor rightMotor;&lt;br /&gt;
&lt;br /&gt;
void setup(){  // this is our „main“ setup Function&lt;br /&gt;
leftMotor.setup(3,4,5);  // assign the pin numbers for each motor in the setup Function: setup(int newForwardPin, int newReversePin, int newThrottlePin)&lt;br /&gt;
rightMotor.setup(6,7,8);&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
void loop(){  // this is our „main“ loop Function where concrete actions are executed. For example:&lt;br /&gt;
// Start backwards, slow down and accelerate forwards &lt;br /&gt;
for (int i =-255, i&amp;lt;=255;i++){&lt;br /&gt;
leftMotor.setThrottle(i);&lt;br /&gt;
rightMotor.setThrottle(i);&lt;br /&gt;
};&lt;br /&gt;
// Start forwards, slow down and accelerate backwards&lt;br /&gt;
for (int i =255, i&amp;gt;=-255;i--){&lt;br /&gt;
leftMotor.setThrottle(i);&lt;br /&gt;
rightMotor.setThrottle(i);&lt;br /&gt;
};&lt;br /&gt;
};&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Organizing classes in separate files==&lt;br /&gt;
&lt;br /&gt;
We can improve our program structure by putting classes in separate files.&lt;br /&gt;
&lt;br /&gt;
1)&lt;br /&gt;
Click on the arrow in the right corner in order to add a new file.&lt;br /&gt;
Select „new Tab“.&lt;br /&gt;
&lt;br /&gt;
----BILD----&lt;br /&gt;
&lt;br /&gt;
2) &lt;br /&gt;
Enter a filename at the bottom of the window. &lt;br /&gt;
It must end with .h !&lt;br /&gt;
In our case I suggest the name motorControl.h.&lt;br /&gt;
&lt;br /&gt;
3) &lt;br /&gt;
Enter the first line:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
#include „Arduino.h“&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This line „links“ the file to the Arduino-specific features.&lt;br /&gt;
Now we can include the code of our class.&lt;br /&gt;
&lt;br /&gt;
4)&lt;br /&gt;
Go back to your main file.&lt;br /&gt;
Now you have to „link“ the new file to your main file in order to use the features of our class.&lt;br /&gt;
Include the following line in the top of your main file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
#include „MotorControl.h“&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
and write the rest of your program as usual.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==More details on the concept==&lt;br /&gt;
&lt;br /&gt;
Classes can build up on each other (inheritance)&lt;br /&gt;
&lt;br /&gt;
In the beginning we promised that it is possible to replace different motor drivers without changing the rest of the program.&lt;br /&gt;
Classes can indeed include other Objects in the form of „member variables“.&lt;br /&gt;
&lt;br /&gt;
C++ allows class declarations and the code for included Functions to be be placed in different files. &lt;br /&gt;
If you want to know more about that you can read this article about creating libraries in Arduino: [http://arduino.cc/en/Hacking/LibraryTutorial http://arduino.cc/en/Hacking/LibraryTutorial ]&lt;/div&gt;</summary>
		<author><name>Veja6203</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90124</id>
		<title>GMU:Functions and Classes (Arduino)</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90124"/>
		<updated>2017-03-28T11:27:17Z</updated>

		<summary type="html">&lt;p&gt;Veja6203: /* Classes are Data-types */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Motivation==&lt;br /&gt;
&lt;br /&gt;
Soon after starting to write the program for your robot you will encounter some typical problems:&lt;br /&gt;
&lt;br /&gt;
* clarity: the bigger the program gets the harder it is to keep the general overview&lt;br /&gt;
* decoupling: you only want to change a certain part of the program without influencing all the rest&lt;br /&gt;
* recyclability: there are several similar parts in your robot for which you would like to reuse particular sections of your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These problems reach back to the beginning of programming and their solution is an art and a science at the same time.&lt;br /&gt;
It generally helps a lot to separate your program into single subunits that are relatively independent from each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example: Controlling Motors==&lt;br /&gt;
&lt;br /&gt;
The [http://arduino.cc/de/Reference/FunctionDeclaration function] is an enormous useful tool that can help you structuring your code. Functions allow you to sum up several operations under the same command. This command can be called again and again without knowing about or duplicating the included code. &lt;br /&gt;
&lt;br /&gt;
Here is an example for a function for setting the speed of a motor that is connected to an H-bridge:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD1.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now (and for every prospective motor movement) we only need to write one single line in order to for instance setting the left wheels speed:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD2.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This already saves us a lot of typing –&lt;br /&gt;
But one thing still seems quite laborious: we have to know the exact pin numbers every time we want to change the speed.&lt;br /&gt;
&lt;br /&gt;
Imagine a program in which similar function calls are distributed all over. &lt;br /&gt;
In case of a hardware update you would have to find every single function call and change the parameters manually. &lt;br /&gt;
This effort could surely be spent for more useful things..&lt;br /&gt;
&lt;br /&gt;
It would be ideal to find a way of calling a certain function that only offers the most useful parameters (like setting the speed) and which handles technical details (switching pins on and off) internally.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Possible solution: Data and code in one package – „Classes“ and „Objects“==&lt;br /&gt;
&lt;br /&gt;
C++ (and also Arduino) provides a specific feature that can solve our problem: Classes and Objects&lt;br /&gt;
&lt;br /&gt;
A Class predefines common qualities of a group of Objects. &lt;br /&gt;
It for instance determines that every motor has the possibility to exert a certain amount of throttle. &lt;br /&gt;
The corresponding program could look like this:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD3.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now the computer knows that there is a class called „Motor“.&lt;br /&gt;
This class (class) provides a function called „setThrottle“ that is called as an argument by using a number (int) and that does not return anything (void).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Classes are Data-types===&lt;br /&gt;
&lt;br /&gt;
We can use our „Motor“ - class the same way we are using other data - types (int, long, float).&amp;lt;p&amp;gt;&lt;br /&gt;
The following lines use that quality in order to implement two motors:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD4.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Calling inner functions of a class (Methods)===&lt;br /&gt;
&lt;br /&gt;
Imagine we want to drive the left motor with full throttle whereas the right motor should stop completely. &lt;br /&gt;
This can be expressed as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;// the objetcs name „leftMotor“ and the herein implemented function „setThrottle“ are separated by a dot.&lt;br /&gt;
leftMotor.setThrottle(255);&lt;br /&gt;
rightMotor.setThrottle(0);&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A positive side effect: your program gains readability by picking distinct names for your Objects and Methods.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Classes can contain other variables that can only be accessed „internally“===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do the Objects „leftMotor“ and „rightMotor“ know which pins they want to switch on and off?&lt;br /&gt;
&lt;br /&gt;
Until now our „Motor“ class is quite abstract since it does not contain this information. &lt;br /&gt;
A class that should conduct practical actions needs further variables (concrete pin numbers) and lines of code that describe what to do exactly.&lt;br /&gt;
We can simply include both things in the class definition:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
class MotoMamaMotor {&lt;br /&gt;
...&lt;br /&gt;
private: // the following definitions are only of „internal use“ for the class itself       &lt;br /&gt;
int forwardPin; //  c &lt;br /&gt;
int reversePin;&lt;br /&gt;
int throttlePin;&lt;br /&gt;
...&lt;br /&gt;
};&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do we include the pin numbers into the Object if they are not visible from the outside?&lt;br /&gt;
We simply write a „setup“ Function for the class:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
class MotoMamaMotor {&lt;br /&gt;
private:&lt;br /&gt;
...&lt;br /&gt;
public: //  we want the setup-function to be accessible from the outside.&lt;br /&gt;
void setup (int newForwardPin, int newReversePin, int newThrottlePin){&lt;br /&gt;
// we remember the pins for future use          &lt;br /&gt;
forwardPin=newForwardPin;&lt;br /&gt;
reversePin=newReversePin;&lt;br /&gt;
throttlePin=newThrottlePin;&lt;br /&gt;
// and at the same time we initialize the outputs ! &lt;br /&gt;
digitalWrite(throttlePin,LOW); //  so that the motors don’t spin directly from the beginning .. &lt;br /&gt;
pinMode(forwardPin,OUTPUT);&lt;br /&gt;
pinMode(reversePin,OUTPUT);&lt;br /&gt;
pinMode(throttlePin,OUTPUT);&lt;br /&gt;
}&lt;br /&gt;
...&lt;br /&gt;
};&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==A complete example ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to construct a complete example we only have to include the „speed“-Function (see description above):&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
// Defining a class for motor control &lt;br /&gt;
&lt;br /&gt;
class MotoMamaMotor {&lt;br /&gt;
&lt;br /&gt;
private: // the following definitions are only of „internal use“ for the class itself&lt;br /&gt;
int forwardPin; //Every MotoMamaMotor type Object has its own forwardPin&lt;br /&gt;
int reversePin;&lt;br /&gt;
int throttlePin;&lt;br /&gt;
&lt;br /&gt;
public: // the following qualities and methods are visible from the outside.&lt;br /&gt;
//  This setup-Function has to be called before using the motor control&lt;br /&gt;
void setup(int newForwardPin, int newReversePin, int newThrottlePin){&lt;br /&gt;
// we remember the pins for future use          &lt;br /&gt;
forwardPin=newForwardPin;&lt;br /&gt;
reversePin=newReversePin;&lt;br /&gt;
throttlePin=newThrottlePin;&lt;br /&gt;
// and at the same time we initialize the outputs ! &lt;br /&gt;
digitalWrite(throttlePin,LOW); //  so that the motors don’t spin directly from the beginning .. &lt;br /&gt;
pinMode(forwardPin,OUTPUT);&lt;br /&gt;
pinMode(reversePin,OUTPUT);&lt;br /&gt;
pinMode(throttlePin,OUTPUT);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// this Function allows to control the motor speed &lt;br /&gt;
void setThrottle (int newThrottle){&lt;br /&gt;
if (newThrottle&amp;gt;0){ // should it spin forwards or backwards?&lt;br /&gt;
// spin forwards&lt;br /&gt;
digitalWrite(reversePin,LOW);&lt;br /&gt;
digitalWrite(forwardPin,HIGH);&lt;br /&gt;
}else{&lt;br /&gt;
// spin backwards&lt;br /&gt;
digitalWrite(forwardPin,LOW);&lt;br /&gt;
digitalWrite(reversePin,HIGH);&lt;br /&gt;
}&lt;br /&gt;
// adjust the speed:&lt;br /&gt;
analogWrite(throttlePin, newThrottle);&lt;br /&gt;
}&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
// create two separate MotoMamaMotor type Objects (leftMotor, rightMotor). They can be used as normal variables. &lt;br /&gt;
MotoMamaMotor leftMotor;&lt;br /&gt;
MotoMamaMotor rightMotor;&lt;br /&gt;
&lt;br /&gt;
void setup(){  // this is our „main“ setup Function&lt;br /&gt;
leftMotor.setup(3,4,5);  // assign the pin numbers for each motor in the setup Function: setup(int newForwardPin, int newReversePin, int newThrottlePin)&lt;br /&gt;
rightMotor.setup(6,7,8);&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
void loop(){  // this is our „main“ loop Function where concrete actions are executed. For example:&lt;br /&gt;
// Start backwards, slow down and accelerate forwards &lt;br /&gt;
for (int i =-255, i&amp;lt;=255;i++){&lt;br /&gt;
leftMotor.setThrottle(i);&lt;br /&gt;
rightMotor.setThrottle(i);&lt;br /&gt;
};&lt;br /&gt;
// Start forwards, slow down and accelerate backwards&lt;br /&gt;
for (int i =255, i&amp;gt;=-255;i--){&lt;br /&gt;
leftMotor.setThrottle(i);&lt;br /&gt;
rightMotor.setThrottle(i);&lt;br /&gt;
};&lt;br /&gt;
};&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Organizing classes in separate files==&lt;br /&gt;
&lt;br /&gt;
We can improve our program structure by putting classes in separate files.&lt;br /&gt;
&lt;br /&gt;
1)&lt;br /&gt;
Click on the arrow in the right corner in order to add a new file.&lt;br /&gt;
Select „new Tab“.&lt;br /&gt;
&lt;br /&gt;
----BILD----&lt;br /&gt;
&lt;br /&gt;
2) &lt;br /&gt;
Enter a filename at the bottom of the window. &lt;br /&gt;
It must end with .h !&lt;br /&gt;
In our case I suggest the name motorControl.h.&lt;br /&gt;
&lt;br /&gt;
3) &lt;br /&gt;
Enter the first line:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
#include „Arduino.h“&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This line „links“ the file to the Arduino-specific features.&lt;br /&gt;
Now we can include the code of our class.&lt;br /&gt;
&lt;br /&gt;
4)&lt;br /&gt;
Go back to your main file.&lt;br /&gt;
Now you have to „link“ the new file to your main file in order to use the features of our class.&lt;br /&gt;
Include the following line in the top of your main file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
#include „MotorControl.h“&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
and write the rest of your program as usual.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==More details on the concept==&lt;br /&gt;
&lt;br /&gt;
Classes can build up on each other (inheritance)&lt;br /&gt;
&lt;br /&gt;
In the beginning we promised that it is possible to replace different motor drivers without changing the rest of the program.&lt;br /&gt;
Classes can indeed include other Objects in the form of „member variables“.&lt;br /&gt;
&lt;br /&gt;
C++ allows class declarations and the code for included Functions to be be placed in different files. &lt;br /&gt;
If you want to know more about that you can read this article about creating libraries in Arduino: [http://arduino.cc/en/Hacking/LibraryTutorial http://arduino.cc/en/Hacking/LibraryTutorial ]&lt;/div&gt;</summary>
		<author><name>Veja6203</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=File:OOPARD4.jpg&amp;diff=90123</id>
		<title>File:OOPARD4.jpg</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=File:OOPARD4.jpg&amp;diff=90123"/>
		<updated>2017-03-28T11:26:56Z</updated>

		<summary type="html">&lt;p&gt;Veja6203: File uploaded with MsUpload&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;File uploaded with MsUpload&lt;/div&gt;</summary>
		<author><name>Veja6203</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90122</id>
		<title>GMU:Functions and Classes (Arduino)</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90122"/>
		<updated>2017-03-28T11:25:16Z</updated>

		<summary type="html">&lt;p&gt;Veja6203: /* Classes are Data-types */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Motivation==&lt;br /&gt;
&lt;br /&gt;
Soon after starting to write the program for your robot you will encounter some typical problems:&lt;br /&gt;
&lt;br /&gt;
* clarity: the bigger the program gets the harder it is to keep the general overview&lt;br /&gt;
* decoupling: you only want to change a certain part of the program without influencing all the rest&lt;br /&gt;
* recyclability: there are several similar parts in your robot for which you would like to reuse particular sections of your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These problems reach back to the beginning of programming and their solution is an art and a science at the same time.&lt;br /&gt;
It generally helps a lot to separate your program into single subunits that are relatively independent from each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example: Controlling Motors==&lt;br /&gt;
&lt;br /&gt;
The [http://arduino.cc/de/Reference/FunctionDeclaration function] is an enormous useful tool that can help you structuring your code. Functions allow you to sum up several operations under the same command. This command can be called again and again without knowing about or duplicating the included code. &lt;br /&gt;
&lt;br /&gt;
Here is an example for a function for setting the speed of a motor that is connected to an H-bridge:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD1.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now (and for every prospective motor movement) we only need to write one single line in order to for instance setting the left wheels speed:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD2.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This already saves us a lot of typing –&lt;br /&gt;
But one thing still seems quite laborious: we have to know the exact pin numbers every time we want to change the speed.&lt;br /&gt;
&lt;br /&gt;
Imagine a program in which similar function calls are distributed all over. &lt;br /&gt;
In case of a hardware update you would have to find every single function call and change the parameters manually. &lt;br /&gt;
This effort could surely be spent for more useful things..&lt;br /&gt;
&lt;br /&gt;
It would be ideal to find a way of calling a certain function that only offers the most useful parameters (like setting the speed) and which handles technical details (switching pins on and off) internally.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Possible solution: Data and code in one package – „Classes“ and „Objects“==&lt;br /&gt;
&lt;br /&gt;
C++ (and also Arduino) provides a specific feature that can solve our problem: Classes and Objects&lt;br /&gt;
&lt;br /&gt;
A Class predefines common qualities of a group of Objects. &lt;br /&gt;
It for instance determines that every motor has the possibility to exert a certain amount of throttle. &lt;br /&gt;
The corresponding program could look like this:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD3.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now the computer knows that there is a class called „Motor“.&lt;br /&gt;
This class (class) provides a function called „setThrottle“ that is called as an argument by using a number (int) and that does not return anything (void).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Classes are Data-types===&lt;br /&gt;
&lt;br /&gt;
We can use our „Motor“ - class the same way we are using other data - types (int, long, float).&amp;lt;p&amp;gt;&lt;br /&gt;
The following lines use that quality in order to implement two motors:&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD4.jpg]]&lt;br /&gt;
&lt;br /&gt;
===Calling inner functions of a class (Methods)===&lt;br /&gt;
&lt;br /&gt;
Imagine we want to drive the left motor with full throttle whereas the right motor should stop completely. &lt;br /&gt;
This can be expressed as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;// the objetcs name „leftMotor“ and the herein implemented function „setThrottle“ are separated by a dot.&lt;br /&gt;
leftMotor.setThrottle(255);&lt;br /&gt;
rightMotor.setThrottle(0);&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A positive side effect: your program gains readability by picking distinct names for your Objects and Methods.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Classes can contain other variables that can only be accessed „internally“===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do the Objects „leftMotor“ and „rightMotor“ know which pins they want to switch on and off?&lt;br /&gt;
&lt;br /&gt;
Until now our „Motor“ class is quite abstract since it does not contain this information. &lt;br /&gt;
A class that should conduct practical actions needs further variables (concrete pin numbers) and lines of code that describe what to do exactly.&lt;br /&gt;
We can simply include both things in the class definition:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
class MotoMamaMotor {&lt;br /&gt;
...&lt;br /&gt;
private: // the following definitions are only of „internal use“ for the class itself       &lt;br /&gt;
int forwardPin; //  c &lt;br /&gt;
int reversePin;&lt;br /&gt;
int throttlePin;&lt;br /&gt;
...&lt;br /&gt;
};&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do we include the pin numbers into the Object if they are not visible from the outside?&lt;br /&gt;
We simply write a „setup“ Function for the class:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
class MotoMamaMotor {&lt;br /&gt;
private:&lt;br /&gt;
...&lt;br /&gt;
public: //  we want the setup-function to be accessible from the outside.&lt;br /&gt;
void setup (int newForwardPin, int newReversePin, int newThrottlePin){&lt;br /&gt;
// we remember the pins for future use          &lt;br /&gt;
forwardPin=newForwardPin;&lt;br /&gt;
reversePin=newReversePin;&lt;br /&gt;
throttlePin=newThrottlePin;&lt;br /&gt;
// and at the same time we initialize the outputs ! &lt;br /&gt;
digitalWrite(throttlePin,LOW); //  so that the motors don’t spin directly from the beginning .. &lt;br /&gt;
pinMode(forwardPin,OUTPUT);&lt;br /&gt;
pinMode(reversePin,OUTPUT);&lt;br /&gt;
pinMode(throttlePin,OUTPUT);&lt;br /&gt;
}&lt;br /&gt;
...&lt;br /&gt;
};&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==A complete example ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to construct a complete example we only have to include the „speed“-Function (see description above):&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
// Defining a class for motor control &lt;br /&gt;
&lt;br /&gt;
class MotoMamaMotor {&lt;br /&gt;
&lt;br /&gt;
private: // the following definitions are only of „internal use“ for the class itself&lt;br /&gt;
int forwardPin; //Every MotoMamaMotor type Object has its own forwardPin&lt;br /&gt;
int reversePin;&lt;br /&gt;
int throttlePin;&lt;br /&gt;
&lt;br /&gt;
public: // the following qualities and methods are visible from the outside.&lt;br /&gt;
//  This setup-Function has to be called before using the motor control&lt;br /&gt;
void setup(int newForwardPin, int newReversePin, int newThrottlePin){&lt;br /&gt;
// we remember the pins for future use          &lt;br /&gt;
forwardPin=newForwardPin;&lt;br /&gt;
reversePin=newReversePin;&lt;br /&gt;
throttlePin=newThrottlePin;&lt;br /&gt;
// and at the same time we initialize the outputs ! &lt;br /&gt;
digitalWrite(throttlePin,LOW); //  so that the motors don’t spin directly from the beginning .. &lt;br /&gt;
pinMode(forwardPin,OUTPUT);&lt;br /&gt;
pinMode(reversePin,OUTPUT);&lt;br /&gt;
pinMode(throttlePin,OUTPUT);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// this Function allows to control the motor speed &lt;br /&gt;
void setThrottle (int newThrottle){&lt;br /&gt;
if (newThrottle&amp;gt;0){ // should it spin forwards or backwards?&lt;br /&gt;
// spin forwards&lt;br /&gt;
digitalWrite(reversePin,LOW);&lt;br /&gt;
digitalWrite(forwardPin,HIGH);&lt;br /&gt;
}else{&lt;br /&gt;
// spin backwards&lt;br /&gt;
digitalWrite(forwardPin,LOW);&lt;br /&gt;
digitalWrite(reversePin,HIGH);&lt;br /&gt;
}&lt;br /&gt;
// adjust the speed:&lt;br /&gt;
analogWrite(throttlePin, newThrottle);&lt;br /&gt;
}&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
// create two separate MotoMamaMotor type Objects (leftMotor, rightMotor). They can be used as normal variables. &lt;br /&gt;
MotoMamaMotor leftMotor;&lt;br /&gt;
MotoMamaMotor rightMotor;&lt;br /&gt;
&lt;br /&gt;
void setup(){  // this is our „main“ setup Function&lt;br /&gt;
leftMotor.setup(3,4,5);  // assign the pin numbers for each motor in the setup Function: setup(int newForwardPin, int newReversePin, int newThrottlePin)&lt;br /&gt;
rightMotor.setup(6,7,8);&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
void loop(){  // this is our „main“ loop Function where concrete actions are executed. For example:&lt;br /&gt;
// Start backwards, slow down and accelerate forwards &lt;br /&gt;
for (int i =-255, i&amp;lt;=255;i++){&lt;br /&gt;
leftMotor.setThrottle(i);&lt;br /&gt;
rightMotor.setThrottle(i);&lt;br /&gt;
};&lt;br /&gt;
// Start forwards, slow down and accelerate backwards&lt;br /&gt;
for (int i =255, i&amp;gt;=-255;i--){&lt;br /&gt;
leftMotor.setThrottle(i);&lt;br /&gt;
rightMotor.setThrottle(i);&lt;br /&gt;
};&lt;br /&gt;
};&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Organizing classes in separate files==&lt;br /&gt;
&lt;br /&gt;
We can improve our program structure by putting classes in separate files.&lt;br /&gt;
&lt;br /&gt;
1)&lt;br /&gt;
Click on the arrow in the right corner in order to add a new file.&lt;br /&gt;
Select „new Tab“.&lt;br /&gt;
&lt;br /&gt;
----BILD----&lt;br /&gt;
&lt;br /&gt;
2) &lt;br /&gt;
Enter a filename at the bottom of the window. &lt;br /&gt;
It must end with .h !&lt;br /&gt;
In our case I suggest the name motorControl.h.&lt;br /&gt;
&lt;br /&gt;
3) &lt;br /&gt;
Enter the first line:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
#include „Arduino.h“&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This line „links“ the file to the Arduino-specific features.&lt;br /&gt;
Now we can include the code of our class.&lt;br /&gt;
&lt;br /&gt;
4)&lt;br /&gt;
Go back to your main file.&lt;br /&gt;
Now you have to „link“ the new file to your main file in order to use the features of our class.&lt;br /&gt;
Include the following line in the top of your main file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
#include „MotorControl.h“&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
and write the rest of your program as usual.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==More details on the concept==&lt;br /&gt;
&lt;br /&gt;
Classes can build up on each other (inheritance)&lt;br /&gt;
&lt;br /&gt;
In the beginning we promised that it is possible to replace different motor drivers without changing the rest of the program.&lt;br /&gt;
Classes can indeed include other Objects in the form of „member variables“.&lt;br /&gt;
&lt;br /&gt;
C++ allows class declarations and the code for included Functions to be be placed in different files. &lt;br /&gt;
If you want to know more about that you can read this article about creating libraries in Arduino: [http://arduino.cc/en/Hacking/LibraryTutorial http://arduino.cc/en/Hacking/LibraryTutorial ]&lt;/div&gt;</summary>
		<author><name>Veja6203</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90121</id>
		<title>GMU:Functions and Classes (Arduino)</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90121"/>
		<updated>2017-03-28T11:22:44Z</updated>

		<summary type="html">&lt;p&gt;Veja6203: /* Possible solution: Data and code in one package – „Classes“ and „Objects“ */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Motivation==&lt;br /&gt;
&lt;br /&gt;
Soon after starting to write the program for your robot you will encounter some typical problems:&lt;br /&gt;
&lt;br /&gt;
* clarity: the bigger the program gets the harder it is to keep the general overview&lt;br /&gt;
* decoupling: you only want to change a certain part of the program without influencing all the rest&lt;br /&gt;
* recyclability: there are several similar parts in your robot for which you would like to reuse particular sections of your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These problems reach back to the beginning of programming and their solution is an art and a science at the same time.&lt;br /&gt;
It generally helps a lot to separate your program into single subunits that are relatively independent from each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example: Controlling Motors==&lt;br /&gt;
&lt;br /&gt;
The [http://arduino.cc/de/Reference/FunctionDeclaration function] is an enormous useful tool that can help you structuring your code. Functions allow you to sum up several operations under the same command. This command can be called again and again without knowing about or duplicating the included code. &lt;br /&gt;
&lt;br /&gt;
Here is an example for a function for setting the speed of a motor that is connected to an H-bridge:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD1.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now (and for every prospective motor movement) we only need to write one single line in order to for instance setting the left wheels speed:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD2.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This already saves us a lot of typing –&lt;br /&gt;
But one thing still seems quite laborious: we have to know the exact pin numbers every time we want to change the speed.&lt;br /&gt;
&lt;br /&gt;
Imagine a program in which similar function calls are distributed all over. &lt;br /&gt;
In case of a hardware update you would have to find every single function call and change the parameters manually. &lt;br /&gt;
This effort could surely be spent for more useful things..&lt;br /&gt;
&lt;br /&gt;
It would be ideal to find a way of calling a certain function that only offers the most useful parameters (like setting the speed) and which handles technical details (switching pins on and off) internally.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Possible solution: Data and code in one package – „Classes“ and „Objects“==&lt;br /&gt;
&lt;br /&gt;
C++ (and also Arduino) provides a specific feature that can solve our problem: Classes and Objects&lt;br /&gt;
&lt;br /&gt;
A Class predefines common qualities of a group of Objects. &lt;br /&gt;
It for instance determines that every motor has the possibility to exert a certain amount of throttle. &lt;br /&gt;
The corresponding program could look like this:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD3.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now the computer knows that there is a class called „Motor“.&lt;br /&gt;
This class (class) provides a function called „setThrottle“ that is called as an argument by using a number (int) and that does not return anything (void).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Classes are Data-types===&lt;br /&gt;
&lt;br /&gt;
We can use our „Motor“ - class the same way we are using other data - types (int, long, float).&lt;br /&gt;
The following lines use that quality in order to implement two motors:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Motor leftMotor; //  declare an object of the type „Motor“ called „leftMotor“ &lt;br /&gt;
Motor rightMotor; //  declare another object of the type „Motor“ called „rightMotor“ &lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Calling inner functions of a class (Methods)===&lt;br /&gt;
&lt;br /&gt;
Imagine we want to drive the left motor with full throttle whereas the right motor should stop completely. &lt;br /&gt;
This can be expressed as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;// the objetcs name „leftMotor“ and the herein implemented function „setThrottle“ are separated by a dot.&lt;br /&gt;
leftMotor.setThrottle(255);&lt;br /&gt;
rightMotor.setThrottle(0);&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A positive side effect: your program gains readability by picking distinct names for your Objects and Methods.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Classes can contain other variables that can only be accessed „internally“===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do the Objects „leftMotor“ and „rightMotor“ know which pins they want to switch on and off?&lt;br /&gt;
&lt;br /&gt;
Until now our „Motor“ class is quite abstract since it does not contain this information. &lt;br /&gt;
A class that should conduct practical actions needs further variables (concrete pin numbers) and lines of code that describe what to do exactly.&lt;br /&gt;
We can simply include both things in the class definition:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
class MotoMamaMotor {&lt;br /&gt;
...&lt;br /&gt;
private: // the following definitions are only of „internal use“ for the class itself       &lt;br /&gt;
int forwardPin; //  c &lt;br /&gt;
int reversePin;&lt;br /&gt;
int throttlePin;&lt;br /&gt;
...&lt;br /&gt;
};&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do we include the pin numbers into the Object if they are not visible from the outside?&lt;br /&gt;
We simply write a „setup“ Function for the class:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
class MotoMamaMotor {&lt;br /&gt;
private:&lt;br /&gt;
...&lt;br /&gt;
public: //  we want the setup-function to be accessible from the outside.&lt;br /&gt;
void setup (int newForwardPin, int newReversePin, int newThrottlePin){&lt;br /&gt;
// we remember the pins for future use          &lt;br /&gt;
forwardPin=newForwardPin;&lt;br /&gt;
reversePin=newReversePin;&lt;br /&gt;
throttlePin=newThrottlePin;&lt;br /&gt;
// and at the same time we initialize the outputs ! &lt;br /&gt;
digitalWrite(throttlePin,LOW); //  so that the motors don’t spin directly from the beginning .. &lt;br /&gt;
pinMode(forwardPin,OUTPUT);&lt;br /&gt;
pinMode(reversePin,OUTPUT);&lt;br /&gt;
pinMode(throttlePin,OUTPUT);&lt;br /&gt;
}&lt;br /&gt;
...&lt;br /&gt;
};&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==A complete example ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to construct a complete example we only have to include the „speed“-Function (see description above):&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
// Defining a class for motor control &lt;br /&gt;
&lt;br /&gt;
class MotoMamaMotor {&lt;br /&gt;
&lt;br /&gt;
private: // the following definitions are only of „internal use“ for the class itself&lt;br /&gt;
int forwardPin; //Every MotoMamaMotor type Object has its own forwardPin&lt;br /&gt;
int reversePin;&lt;br /&gt;
int throttlePin;&lt;br /&gt;
&lt;br /&gt;
public: // the following qualities and methods are visible from the outside.&lt;br /&gt;
//  This setup-Function has to be called before using the motor control&lt;br /&gt;
void setup(int newForwardPin, int newReversePin, int newThrottlePin){&lt;br /&gt;
// we remember the pins for future use          &lt;br /&gt;
forwardPin=newForwardPin;&lt;br /&gt;
reversePin=newReversePin;&lt;br /&gt;
throttlePin=newThrottlePin;&lt;br /&gt;
// and at the same time we initialize the outputs ! &lt;br /&gt;
digitalWrite(throttlePin,LOW); //  so that the motors don’t spin directly from the beginning .. &lt;br /&gt;
pinMode(forwardPin,OUTPUT);&lt;br /&gt;
pinMode(reversePin,OUTPUT);&lt;br /&gt;
pinMode(throttlePin,OUTPUT);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// this Function allows to control the motor speed &lt;br /&gt;
void setThrottle (int newThrottle){&lt;br /&gt;
if (newThrottle&amp;gt;0){ // should it spin forwards or backwards?&lt;br /&gt;
// spin forwards&lt;br /&gt;
digitalWrite(reversePin,LOW);&lt;br /&gt;
digitalWrite(forwardPin,HIGH);&lt;br /&gt;
}else{&lt;br /&gt;
// spin backwards&lt;br /&gt;
digitalWrite(forwardPin,LOW);&lt;br /&gt;
digitalWrite(reversePin,HIGH);&lt;br /&gt;
}&lt;br /&gt;
// adjust the speed:&lt;br /&gt;
analogWrite(throttlePin, newThrottle);&lt;br /&gt;
}&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
// create two separate MotoMamaMotor type Objects (leftMotor, rightMotor). They can be used as normal variables. &lt;br /&gt;
MotoMamaMotor leftMotor;&lt;br /&gt;
MotoMamaMotor rightMotor;&lt;br /&gt;
&lt;br /&gt;
void setup(){  // this is our „main“ setup Function&lt;br /&gt;
leftMotor.setup(3,4,5);  // assign the pin numbers for each motor in the setup Function: setup(int newForwardPin, int newReversePin, int newThrottlePin)&lt;br /&gt;
rightMotor.setup(6,7,8);&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
void loop(){  // this is our „main“ loop Function where concrete actions are executed. For example:&lt;br /&gt;
// Start backwards, slow down and accelerate forwards &lt;br /&gt;
for (int i =-255, i&amp;lt;=255;i++){&lt;br /&gt;
leftMotor.setThrottle(i);&lt;br /&gt;
rightMotor.setThrottle(i);&lt;br /&gt;
};&lt;br /&gt;
// Start forwards, slow down and accelerate backwards&lt;br /&gt;
for (int i =255, i&amp;gt;=-255;i--){&lt;br /&gt;
leftMotor.setThrottle(i);&lt;br /&gt;
rightMotor.setThrottle(i);&lt;br /&gt;
};&lt;br /&gt;
};&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Organizing classes in separate files==&lt;br /&gt;
&lt;br /&gt;
We can improve our program structure by putting classes in separate files.&lt;br /&gt;
&lt;br /&gt;
1)&lt;br /&gt;
Click on the arrow in the right corner in order to add a new file.&lt;br /&gt;
Select „new Tab“.&lt;br /&gt;
&lt;br /&gt;
----BILD----&lt;br /&gt;
&lt;br /&gt;
2) &lt;br /&gt;
Enter a filename at the bottom of the window. &lt;br /&gt;
It must end with .h !&lt;br /&gt;
In our case I suggest the name motorControl.h.&lt;br /&gt;
&lt;br /&gt;
3) &lt;br /&gt;
Enter the first line:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
#include „Arduino.h“&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This line „links“ the file to the Arduino-specific features.&lt;br /&gt;
Now we can include the code of our class.&lt;br /&gt;
&lt;br /&gt;
4)&lt;br /&gt;
Go back to your main file.&lt;br /&gt;
Now you have to „link“ the new file to your main file in order to use the features of our class.&lt;br /&gt;
Include the following line in the top of your main file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
#include „MotorControl.h“&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
and write the rest of your program as usual.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==More details on the concept==&lt;br /&gt;
&lt;br /&gt;
Classes can build up on each other (inheritance)&lt;br /&gt;
&lt;br /&gt;
In the beginning we promised that it is possible to replace different motor drivers without changing the rest of the program.&lt;br /&gt;
Classes can indeed include other Objects in the form of „member variables“.&lt;br /&gt;
&lt;br /&gt;
C++ allows class declarations and the code for included Functions to be be placed in different files. &lt;br /&gt;
If you want to know more about that you can read this article about creating libraries in Arduino: [http://arduino.cc/en/Hacking/LibraryTutorial http://arduino.cc/en/Hacking/LibraryTutorial ]&lt;/div&gt;</summary>
		<author><name>Veja6203</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90120</id>
		<title>GMU:Functions and Classes (Arduino)</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90120"/>
		<updated>2017-03-28T11:22:13Z</updated>

		<summary type="html">&lt;p&gt;Veja6203: /* Possible solution: Data and code in one package „Classes“ and „Objects“ */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Motivation==&lt;br /&gt;
&lt;br /&gt;
Soon after starting to write the program for your robot you will encounter some typical problems:&lt;br /&gt;
&lt;br /&gt;
* clarity: the bigger the program gets the harder it is to keep the general overview&lt;br /&gt;
* decoupling: you only want to change a certain part of the program without influencing all the rest&lt;br /&gt;
* recyclability: there are several similar parts in your robot for which you would like to reuse particular sections of your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These problems reach back to the beginning of programming and their solution is an art and a science at the same time.&lt;br /&gt;
It generally helps a lot to separate your program into single subunits that are relatively independent from each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example: Controlling Motors==&lt;br /&gt;
&lt;br /&gt;
The [http://arduino.cc/de/Reference/FunctionDeclaration function] is an enormous useful tool that can help you structuring your code. Functions allow you to sum up several operations under the same command. This command can be called again and again without knowing about or duplicating the included code. &lt;br /&gt;
&lt;br /&gt;
Here is an example for a function for setting the speed of a motor that is connected to an H-bridge:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD1.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now (and for every prospective motor movement) we only need to write one single line in order to for instance setting the left wheels speed:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD2.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This already saves us a lot of typing –&lt;br /&gt;
But one thing still seems quite laborious: we have to know the exact pin numbers every time we want to change the speed.&lt;br /&gt;
&lt;br /&gt;
Imagine a program in which similar function calls are distributed all over. &lt;br /&gt;
In case of a hardware update you would have to find every single function call and change the parameters manually. &lt;br /&gt;
This effort could surely be spent for more useful things..&lt;br /&gt;
&lt;br /&gt;
It would be ideal to find a way of calling a certain function that only offers the most useful parameters (like setting the speed) and which handles technical details (switching pins on and off) internally.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Possible solution: Data and code in one package – „Classes“ and „Objects“==&lt;br /&gt;
&lt;br /&gt;
C++ (and also Arduino) provides a specific feature that can solve our problem: Classes and Objects&lt;br /&gt;
&lt;br /&gt;
A Class predefines common qualities of a group of Objects. &lt;br /&gt;
It for instance determines that every motor has the possibility to exert a certain amount of throttle. &lt;br /&gt;
The corresponding program could look like this:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD3]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now the computer knows that there is a class called „Motor“.&lt;br /&gt;
This class (class) provides a function called „setThrottle“ that is called as an argument by using a number (int) and that does not return anything (void).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Classes are Data-types===&lt;br /&gt;
&lt;br /&gt;
We can use our „Motor“ - class the same way we are using other data - types (int, long, float).&lt;br /&gt;
The following lines use that quality in order to implement two motors:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Motor leftMotor; //  declare an object of the type „Motor“ called „leftMotor“ &lt;br /&gt;
Motor rightMotor; //  declare another object of the type „Motor“ called „rightMotor“ &lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Calling inner functions of a class (Methods)===&lt;br /&gt;
&lt;br /&gt;
Imagine we want to drive the left motor with full throttle whereas the right motor should stop completely. &lt;br /&gt;
This can be expressed as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;// the objetcs name „leftMotor“ and the herein implemented function „setThrottle“ are separated by a dot.&lt;br /&gt;
leftMotor.setThrottle(255);&lt;br /&gt;
rightMotor.setThrottle(0);&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A positive side effect: your program gains readability by picking distinct names for your Objects and Methods.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Classes can contain other variables that can only be accessed „internally“===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do the Objects „leftMotor“ and „rightMotor“ know which pins they want to switch on and off?&lt;br /&gt;
&lt;br /&gt;
Until now our „Motor“ class is quite abstract since it does not contain this information. &lt;br /&gt;
A class that should conduct practical actions needs further variables (concrete pin numbers) and lines of code that describe what to do exactly.&lt;br /&gt;
We can simply include both things in the class definition:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
class MotoMamaMotor {&lt;br /&gt;
...&lt;br /&gt;
private: // the following definitions are only of „internal use“ for the class itself       &lt;br /&gt;
int forwardPin; //  c &lt;br /&gt;
int reversePin;&lt;br /&gt;
int throttlePin;&lt;br /&gt;
...&lt;br /&gt;
};&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do we include the pin numbers into the Object if they are not visible from the outside?&lt;br /&gt;
We simply write a „setup“ Function for the class:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
class MotoMamaMotor {&lt;br /&gt;
private:&lt;br /&gt;
...&lt;br /&gt;
public: //  we want the setup-function to be accessible from the outside.&lt;br /&gt;
void setup (int newForwardPin, int newReversePin, int newThrottlePin){&lt;br /&gt;
// we remember the pins for future use          &lt;br /&gt;
forwardPin=newForwardPin;&lt;br /&gt;
reversePin=newReversePin;&lt;br /&gt;
throttlePin=newThrottlePin;&lt;br /&gt;
// and at the same time we initialize the outputs ! &lt;br /&gt;
digitalWrite(throttlePin,LOW); //  so that the motors don’t spin directly from the beginning .. &lt;br /&gt;
pinMode(forwardPin,OUTPUT);&lt;br /&gt;
pinMode(reversePin,OUTPUT);&lt;br /&gt;
pinMode(throttlePin,OUTPUT);&lt;br /&gt;
}&lt;br /&gt;
...&lt;br /&gt;
};&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==A complete example ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to construct a complete example we only have to include the „speed“-Function (see description above):&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
// Defining a class for motor control &lt;br /&gt;
&lt;br /&gt;
class MotoMamaMotor {&lt;br /&gt;
&lt;br /&gt;
private: // the following definitions are only of „internal use“ for the class itself&lt;br /&gt;
int forwardPin; //Every MotoMamaMotor type Object has its own forwardPin&lt;br /&gt;
int reversePin;&lt;br /&gt;
int throttlePin;&lt;br /&gt;
&lt;br /&gt;
public: // the following qualities and methods are visible from the outside.&lt;br /&gt;
//  This setup-Function has to be called before using the motor control&lt;br /&gt;
void setup(int newForwardPin, int newReversePin, int newThrottlePin){&lt;br /&gt;
// we remember the pins for future use          &lt;br /&gt;
forwardPin=newForwardPin;&lt;br /&gt;
reversePin=newReversePin;&lt;br /&gt;
throttlePin=newThrottlePin;&lt;br /&gt;
// and at the same time we initialize the outputs ! &lt;br /&gt;
digitalWrite(throttlePin,LOW); //  so that the motors don’t spin directly from the beginning .. &lt;br /&gt;
pinMode(forwardPin,OUTPUT);&lt;br /&gt;
pinMode(reversePin,OUTPUT);&lt;br /&gt;
pinMode(throttlePin,OUTPUT);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// this Function allows to control the motor speed &lt;br /&gt;
void setThrottle (int newThrottle){&lt;br /&gt;
if (newThrottle&amp;gt;0){ // should it spin forwards or backwards?&lt;br /&gt;
// spin forwards&lt;br /&gt;
digitalWrite(reversePin,LOW);&lt;br /&gt;
digitalWrite(forwardPin,HIGH);&lt;br /&gt;
}else{&lt;br /&gt;
// spin backwards&lt;br /&gt;
digitalWrite(forwardPin,LOW);&lt;br /&gt;
digitalWrite(reversePin,HIGH);&lt;br /&gt;
}&lt;br /&gt;
// adjust the speed:&lt;br /&gt;
analogWrite(throttlePin, newThrottle);&lt;br /&gt;
}&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
// create two separate MotoMamaMotor type Objects (leftMotor, rightMotor). They can be used as normal variables. &lt;br /&gt;
MotoMamaMotor leftMotor;&lt;br /&gt;
MotoMamaMotor rightMotor;&lt;br /&gt;
&lt;br /&gt;
void setup(){  // this is our „main“ setup Function&lt;br /&gt;
leftMotor.setup(3,4,5);  // assign the pin numbers for each motor in the setup Function: setup(int newForwardPin, int newReversePin, int newThrottlePin)&lt;br /&gt;
rightMotor.setup(6,7,8);&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
void loop(){  // this is our „main“ loop Function where concrete actions are executed. For example:&lt;br /&gt;
// Start backwards, slow down and accelerate forwards &lt;br /&gt;
for (int i =-255, i&amp;lt;=255;i++){&lt;br /&gt;
leftMotor.setThrottle(i);&lt;br /&gt;
rightMotor.setThrottle(i);&lt;br /&gt;
};&lt;br /&gt;
// Start forwards, slow down and accelerate backwards&lt;br /&gt;
for (int i =255, i&amp;gt;=-255;i--){&lt;br /&gt;
leftMotor.setThrottle(i);&lt;br /&gt;
rightMotor.setThrottle(i);&lt;br /&gt;
};&lt;br /&gt;
};&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Organizing classes in separate files==&lt;br /&gt;
&lt;br /&gt;
We can improve our program structure by putting classes in separate files.&lt;br /&gt;
&lt;br /&gt;
1)&lt;br /&gt;
Click on the arrow in the right corner in order to add a new file.&lt;br /&gt;
Select „new Tab“.&lt;br /&gt;
&lt;br /&gt;
----BILD----&lt;br /&gt;
&lt;br /&gt;
2) &lt;br /&gt;
Enter a filename at the bottom of the window. &lt;br /&gt;
It must end with .h !&lt;br /&gt;
In our case I suggest the name motorControl.h.&lt;br /&gt;
&lt;br /&gt;
3) &lt;br /&gt;
Enter the first line:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
#include „Arduino.h“&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This line „links“ the file to the Arduino-specific features.&lt;br /&gt;
Now we can include the code of our class.&lt;br /&gt;
&lt;br /&gt;
4)&lt;br /&gt;
Go back to your main file.&lt;br /&gt;
Now you have to „link“ the new file to your main file in order to use the features of our class.&lt;br /&gt;
Include the following line in the top of your main file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
#include „MotorControl.h“&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
and write the rest of your program as usual.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==More details on the concept==&lt;br /&gt;
&lt;br /&gt;
Classes can build up on each other (inheritance)&lt;br /&gt;
&lt;br /&gt;
In the beginning we promised that it is possible to replace different motor drivers without changing the rest of the program.&lt;br /&gt;
Classes can indeed include other Objects in the form of „member variables“.&lt;br /&gt;
&lt;br /&gt;
C++ allows class declarations and the code for included Functions to be be placed in different files. &lt;br /&gt;
If you want to know more about that you can read this article about creating libraries in Arduino: [http://arduino.cc/en/Hacking/LibraryTutorial http://arduino.cc/en/Hacking/LibraryTutorial ]&lt;/div&gt;</summary>
		<author><name>Veja6203</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=File:OOPARD3.jpg&amp;diff=90119</id>
		<title>File:OOPARD3.jpg</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=File:OOPARD3.jpg&amp;diff=90119"/>
		<updated>2017-03-28T11:22:08Z</updated>

		<summary type="html">&lt;p&gt;Veja6203: File uploaded with MsUpload&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;File uploaded with MsUpload&lt;/div&gt;</summary>
		<author><name>Veja6203</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90118</id>
		<title>GMU:Functions and Classes (Arduino)</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90118"/>
		<updated>2017-03-28T11:13:46Z</updated>

		<summary type="html">&lt;p&gt;Veja6203: /* Example: Controlling Motors */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Motivation==&lt;br /&gt;
&lt;br /&gt;
Soon after starting to write the program for your robot you will encounter some typical problems:&lt;br /&gt;
&lt;br /&gt;
* clarity: the bigger the program gets the harder it is to keep the general overview&lt;br /&gt;
* decoupling: you only want to change a certain part of the program without influencing all the rest&lt;br /&gt;
* recyclability: there are several similar parts in your robot for which you would like to reuse particular sections of your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These problems reach back to the beginning of programming and their solution is an art and a science at the same time.&lt;br /&gt;
It generally helps a lot to separate your program into single subunits that are relatively independent from each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example: Controlling Motors==&lt;br /&gt;
&lt;br /&gt;
The [http://arduino.cc/de/Reference/FunctionDeclaration function] is an enormous useful tool that can help you structuring your code. Functions allow you to sum up several operations under the same command. This command can be called again and again without knowing about or duplicating the included code. &lt;br /&gt;
&lt;br /&gt;
Here is an example for a function for setting the speed of a motor that is connected to an H-bridge:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD1.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now (and for every prospective motor movement) we only need to write one single line in order to for instance setting the left wheels speed:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD2.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This already saves us a lot of typing –&lt;br /&gt;
But one thing still seems quite laborious: we have to know the exact pin numbers every time we want to change the speed.&lt;br /&gt;
&lt;br /&gt;
Imagine a program in which similar function calls are distributed all over. &lt;br /&gt;
In case of a hardware update you would have to find every single function call and change the parameters manually. &lt;br /&gt;
This effort could surely be spent for more useful things..&lt;br /&gt;
&lt;br /&gt;
It would be ideal to find a way of calling a certain function that only offers the most useful parameters (like setting the speed) and which handles technical details (switching pins on and off) internally.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Possible solution: Data and code in one package „Classes“ and „Objects“==&lt;br /&gt;
&lt;br /&gt;
C++ (and also Arduino) provides a specific feature that can solve our problem: Classes and Objects&lt;br /&gt;
&lt;br /&gt;
A Class predefines common qualities of a group of Objects. &lt;br /&gt;
It for instance determines that every motor has the possibility to exert a certain amount of throttle. &lt;br /&gt;
The corresponding program could look like this:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;class Motor{&lt;br /&gt;
public: // the following qualities and methods are visible from the outside.&lt;br /&gt;
void setThrottle(int newThrottle); // every motor has the possibility to exert trottle.&lt;br /&gt;
}&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now the computer knows that there is a class called „Motor“.&lt;br /&gt;
This class (class) provides a function called „setThrottle“ that is called as an argument by using a number (int) and that does not return anything (void).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Classes are Data-types===&lt;br /&gt;
&lt;br /&gt;
We can use our „Motor“ - class the same way we are using other data - types (int, long, float).&lt;br /&gt;
The following lines use that quality in order to implement two motors:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Motor leftMotor; //  declare an object of the type „Motor“ called „leftMotor“ &lt;br /&gt;
Motor rightMotor; //  declare another object of the type „Motor“ called „rightMotor“ &lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Calling inner functions of a class (Methods)===&lt;br /&gt;
&lt;br /&gt;
Imagine we want to drive the left motor with full throttle whereas the right motor should stop completely. &lt;br /&gt;
This can be expressed as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;// the objetcs name „leftMotor“ and the herein implemented function „setThrottle“ are separated by a dot.&lt;br /&gt;
leftMotor.setThrottle(255);&lt;br /&gt;
rightMotor.setThrottle(0);&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A positive side effect: your program gains readability by picking distinct names for your Objects and Methods.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Classes can contain other variables that can only be accessed „internally“===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do the Objects „leftMotor“ and „rightMotor“ know which pins they want to switch on and off?&lt;br /&gt;
&lt;br /&gt;
Until now our „Motor“ class is quite abstract since it does not contain this information. &lt;br /&gt;
A class that should conduct practical actions needs further variables (concrete pin numbers) and lines of code that describe what to do exactly.&lt;br /&gt;
We can simply include both things in the class definition:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
class MotoMamaMotor {&lt;br /&gt;
...&lt;br /&gt;
private: // the following definitions are only of „internal use“ for the class itself       &lt;br /&gt;
int forwardPin; //  c &lt;br /&gt;
int reversePin;&lt;br /&gt;
int throttlePin;&lt;br /&gt;
...&lt;br /&gt;
};&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do we include the pin numbers into the Object if they are not visible from the outside?&lt;br /&gt;
We simply write a „setup“ Function for the class:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
class MotoMamaMotor {&lt;br /&gt;
private:&lt;br /&gt;
...&lt;br /&gt;
public: //  we want the setup-function to be accessible from the outside.&lt;br /&gt;
void setup (int newForwardPin, int newReversePin, int newThrottlePin){&lt;br /&gt;
// we remember the pins for future use          &lt;br /&gt;
forwardPin=newForwardPin;&lt;br /&gt;
reversePin=newReversePin;&lt;br /&gt;
throttlePin=newThrottlePin;&lt;br /&gt;
// and at the same time we initialize the outputs ! &lt;br /&gt;
digitalWrite(throttlePin,LOW); //  so that the motors don’t spin directly from the beginning .. &lt;br /&gt;
pinMode(forwardPin,OUTPUT);&lt;br /&gt;
pinMode(reversePin,OUTPUT);&lt;br /&gt;
pinMode(throttlePin,OUTPUT);&lt;br /&gt;
}&lt;br /&gt;
...&lt;br /&gt;
};&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==A complete example ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to construct a complete example we only have to include the „speed“-Function (see description above):&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
// Defining a class for motor control &lt;br /&gt;
&lt;br /&gt;
class MotoMamaMotor {&lt;br /&gt;
&lt;br /&gt;
private: // the following definitions are only of „internal use“ for the class itself&lt;br /&gt;
int forwardPin; //Every MotoMamaMotor type Object has its own forwardPin&lt;br /&gt;
int reversePin;&lt;br /&gt;
int throttlePin;&lt;br /&gt;
&lt;br /&gt;
public: // the following qualities and methods are visible from the outside.&lt;br /&gt;
//  This setup-Function has to be called before using the motor control&lt;br /&gt;
void setup(int newForwardPin, int newReversePin, int newThrottlePin){&lt;br /&gt;
// we remember the pins for future use          &lt;br /&gt;
forwardPin=newForwardPin;&lt;br /&gt;
reversePin=newReversePin;&lt;br /&gt;
throttlePin=newThrottlePin;&lt;br /&gt;
// and at the same time we initialize the outputs ! &lt;br /&gt;
digitalWrite(throttlePin,LOW); //  so that the motors don’t spin directly from the beginning .. &lt;br /&gt;
pinMode(forwardPin,OUTPUT);&lt;br /&gt;
pinMode(reversePin,OUTPUT);&lt;br /&gt;
pinMode(throttlePin,OUTPUT);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// this Function allows to control the motor speed &lt;br /&gt;
void setThrottle (int newThrottle){&lt;br /&gt;
if (newThrottle&amp;gt;0){ // should it spin forwards or backwards?&lt;br /&gt;
// spin forwards&lt;br /&gt;
digitalWrite(reversePin,LOW);&lt;br /&gt;
digitalWrite(forwardPin,HIGH);&lt;br /&gt;
}else{&lt;br /&gt;
// spin backwards&lt;br /&gt;
digitalWrite(forwardPin,LOW);&lt;br /&gt;
digitalWrite(reversePin,HIGH);&lt;br /&gt;
}&lt;br /&gt;
// adjust the speed:&lt;br /&gt;
analogWrite(throttlePin, newThrottle);&lt;br /&gt;
}&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
// create two separate MotoMamaMotor type Objects (leftMotor, rightMotor). They can be used as normal variables. &lt;br /&gt;
MotoMamaMotor leftMotor;&lt;br /&gt;
MotoMamaMotor rightMotor;&lt;br /&gt;
&lt;br /&gt;
void setup(){  // this is our „main“ setup Function&lt;br /&gt;
leftMotor.setup(3,4,5);  // assign the pin numbers for each motor in the setup Function: setup(int newForwardPin, int newReversePin, int newThrottlePin)&lt;br /&gt;
rightMotor.setup(6,7,8);&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
void loop(){  // this is our „main“ loop Function where concrete actions are executed. For example:&lt;br /&gt;
// Start backwards, slow down and accelerate forwards &lt;br /&gt;
for (int i =-255, i&amp;lt;=255;i++){&lt;br /&gt;
leftMotor.setThrottle(i);&lt;br /&gt;
rightMotor.setThrottle(i);&lt;br /&gt;
};&lt;br /&gt;
// Start forwards, slow down and accelerate backwards&lt;br /&gt;
for (int i =255, i&amp;gt;=-255;i--){&lt;br /&gt;
leftMotor.setThrottle(i);&lt;br /&gt;
rightMotor.setThrottle(i);&lt;br /&gt;
};&lt;br /&gt;
};&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Organizing classes in separate files==&lt;br /&gt;
&lt;br /&gt;
We can improve our program structure by putting classes in separate files.&lt;br /&gt;
&lt;br /&gt;
1)&lt;br /&gt;
Click on the arrow in the right corner in order to add a new file.&lt;br /&gt;
Select „new Tab“.&lt;br /&gt;
&lt;br /&gt;
----BILD----&lt;br /&gt;
&lt;br /&gt;
2) &lt;br /&gt;
Enter a filename at the bottom of the window. &lt;br /&gt;
It must end with .h !&lt;br /&gt;
In our case I suggest the name motorControl.h.&lt;br /&gt;
&lt;br /&gt;
3) &lt;br /&gt;
Enter the first line:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
#include „Arduino.h“&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This line „links“ the file to the Arduino-specific features.&lt;br /&gt;
Now we can include the code of our class.&lt;br /&gt;
&lt;br /&gt;
4)&lt;br /&gt;
Go back to your main file.&lt;br /&gt;
Now you have to „link“ the new file to your main file in order to use the features of our class.&lt;br /&gt;
Include the following line in the top of your main file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
#include „MotorControl.h“&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
and write the rest of your program as usual.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==More details on the concept==&lt;br /&gt;
&lt;br /&gt;
Classes can build up on each other (inheritance)&lt;br /&gt;
&lt;br /&gt;
In the beginning we promised that it is possible to replace different motor drivers without changing the rest of the program.&lt;br /&gt;
Classes can indeed include other Objects in the form of „member variables“.&lt;br /&gt;
&lt;br /&gt;
C++ allows class declarations and the code for included Functions to be be placed in different files. &lt;br /&gt;
If you want to know more about that you can read this article about creating libraries in Arduino: [http://arduino.cc/en/Hacking/LibraryTutorial http://arduino.cc/en/Hacking/LibraryTutorial ]&lt;/div&gt;</summary>
		<author><name>Veja6203</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90117</id>
		<title>GMU:Functions and Classes (Arduino)</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90117"/>
		<updated>2017-03-28T11:13:00Z</updated>

		<summary type="html">&lt;p&gt;Veja6203: /* Example: Controlling Motors */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Motivation==&lt;br /&gt;
&lt;br /&gt;
Soon after starting to write the program for your robot you will encounter some typical problems:&lt;br /&gt;
&lt;br /&gt;
* clarity: the bigger the program gets the harder it is to keep the general overview&lt;br /&gt;
* decoupling: you only want to change a certain part of the program without influencing all the rest&lt;br /&gt;
* recyclability: there are several similar parts in your robot for which you would like to reuse particular sections of your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These problems reach back to the beginning of programming and their solution is an art and a science at the same time.&lt;br /&gt;
It generally helps a lot to separate your program into single subunits that are relatively independent from each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example: Controlling Motors==&lt;br /&gt;
&lt;br /&gt;
The [http://arduino.cc/de/Reference/FunctionDeclaration function] is an enormous useful tool that can help you structuring your code. Functions allow you to sum up several operations under the same command. This command can be called again and again without knowing about or duplicating the included code. &lt;br /&gt;
&lt;br /&gt;
Here is an example for a function for setting the speed of a motor that is connected to an H-bridge:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD1.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now (and for every prospective motor movement) we only need to write one single line in order to for instance setting the left wheels speed:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD2.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This already saves us a lot of typing –&lt;br /&gt;
But one thing still seems quite laborious: we have to know the exact pin numbers every time we want to change the speed.&lt;br /&gt;
&lt;br /&gt;
Imagine a program in which similar function calls are distributed all over. &lt;br /&gt;
In case of a hardware update you would have to find every single function call and change the parameters manually. &lt;br /&gt;
This effort could surely be spent for more useful things..&lt;br /&gt;
&lt;br /&gt;
It would be ideal to find a way of calling a certain function that only offers the most useful parameters (like setting the speed) and which handles technical details (switching pins on and off) internally.&lt;br /&gt;
&lt;br /&gt;
==Possible solution: Data and code in one package „Classes“ and „Objects“==&lt;br /&gt;
&lt;br /&gt;
C++ (and also Arduino) provides a specific feature that can solve our problem: Classes and Objects&lt;br /&gt;
&lt;br /&gt;
A Class predefines common qualities of a group of Objects. &lt;br /&gt;
It for instance determines that every motor has the possibility to exert a certain amount of throttle. &lt;br /&gt;
The corresponding program could look like this:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;class Motor{&lt;br /&gt;
public: // the following qualities and methods are visible from the outside.&lt;br /&gt;
void setThrottle(int newThrottle); // every motor has the possibility to exert trottle.&lt;br /&gt;
}&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now the computer knows that there is a class called „Motor“.&lt;br /&gt;
This class (class) provides a function called „setThrottle“ that is called as an argument by using a number (int) and that does not return anything (void).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Classes are Data-types===&lt;br /&gt;
&lt;br /&gt;
We can use our „Motor“ - class the same way we are using other data - types (int, long, float).&lt;br /&gt;
The following lines use that quality in order to implement two motors:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Motor leftMotor; //  declare an object of the type „Motor“ called „leftMotor“ &lt;br /&gt;
Motor rightMotor; //  declare another object of the type „Motor“ called „rightMotor“ &lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Calling inner functions of a class (Methods)===&lt;br /&gt;
&lt;br /&gt;
Imagine we want to drive the left motor with full throttle whereas the right motor should stop completely. &lt;br /&gt;
This can be expressed as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;// the objetcs name „leftMotor“ and the herein implemented function „setThrottle“ are separated by a dot.&lt;br /&gt;
leftMotor.setThrottle(255);&lt;br /&gt;
rightMotor.setThrottle(0);&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A positive side effect: your program gains readability by picking distinct names for your Objects and Methods.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Classes can contain other variables that can only be accessed „internally“===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do the Objects „leftMotor“ and „rightMotor“ know which pins they want to switch on and off?&lt;br /&gt;
&lt;br /&gt;
Until now our „Motor“ class is quite abstract since it does not contain this information. &lt;br /&gt;
A class that should conduct practical actions needs further variables (concrete pin numbers) and lines of code that describe what to do exactly.&lt;br /&gt;
We can simply include both things in the class definition:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
class MotoMamaMotor {&lt;br /&gt;
...&lt;br /&gt;
private: // the following definitions are only of „internal use“ for the class itself       &lt;br /&gt;
int forwardPin; //  c &lt;br /&gt;
int reversePin;&lt;br /&gt;
int throttlePin;&lt;br /&gt;
...&lt;br /&gt;
};&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do we include the pin numbers into the Object if they are not visible from the outside?&lt;br /&gt;
We simply write a „setup“ Function for the class:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
class MotoMamaMotor {&lt;br /&gt;
private:&lt;br /&gt;
...&lt;br /&gt;
public: //  we want the setup-function to be accessible from the outside.&lt;br /&gt;
void setup (int newForwardPin, int newReversePin, int newThrottlePin){&lt;br /&gt;
// we remember the pins for future use          &lt;br /&gt;
forwardPin=newForwardPin;&lt;br /&gt;
reversePin=newReversePin;&lt;br /&gt;
throttlePin=newThrottlePin;&lt;br /&gt;
// and at the same time we initialize the outputs ! &lt;br /&gt;
digitalWrite(throttlePin,LOW); //  so that the motors don’t spin directly from the beginning .. &lt;br /&gt;
pinMode(forwardPin,OUTPUT);&lt;br /&gt;
pinMode(reversePin,OUTPUT);&lt;br /&gt;
pinMode(throttlePin,OUTPUT);&lt;br /&gt;
}&lt;br /&gt;
...&lt;br /&gt;
};&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==A complete example ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to construct a complete example we only have to include the „speed“-Function (see description above):&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
// Defining a class for motor control &lt;br /&gt;
&lt;br /&gt;
class MotoMamaMotor {&lt;br /&gt;
&lt;br /&gt;
private: // the following definitions are only of „internal use“ for the class itself&lt;br /&gt;
int forwardPin; //Every MotoMamaMotor type Object has its own forwardPin&lt;br /&gt;
int reversePin;&lt;br /&gt;
int throttlePin;&lt;br /&gt;
&lt;br /&gt;
public: // the following qualities and methods are visible from the outside.&lt;br /&gt;
//  This setup-Function has to be called before using the motor control&lt;br /&gt;
void setup(int newForwardPin, int newReversePin, int newThrottlePin){&lt;br /&gt;
// we remember the pins for future use          &lt;br /&gt;
forwardPin=newForwardPin;&lt;br /&gt;
reversePin=newReversePin;&lt;br /&gt;
throttlePin=newThrottlePin;&lt;br /&gt;
// and at the same time we initialize the outputs ! &lt;br /&gt;
digitalWrite(throttlePin,LOW); //  so that the motors don’t spin directly from the beginning .. &lt;br /&gt;
pinMode(forwardPin,OUTPUT);&lt;br /&gt;
pinMode(reversePin,OUTPUT);&lt;br /&gt;
pinMode(throttlePin,OUTPUT);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// this Function allows to control the motor speed &lt;br /&gt;
void setThrottle (int newThrottle){&lt;br /&gt;
if (newThrottle&amp;gt;0){ // should it spin forwards or backwards?&lt;br /&gt;
// spin forwards&lt;br /&gt;
digitalWrite(reversePin,LOW);&lt;br /&gt;
digitalWrite(forwardPin,HIGH);&lt;br /&gt;
}else{&lt;br /&gt;
// spin backwards&lt;br /&gt;
digitalWrite(forwardPin,LOW);&lt;br /&gt;
digitalWrite(reversePin,HIGH);&lt;br /&gt;
}&lt;br /&gt;
// adjust the speed:&lt;br /&gt;
analogWrite(throttlePin, newThrottle);&lt;br /&gt;
}&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
// create two separate MotoMamaMotor type Objects (leftMotor, rightMotor). They can be used as normal variables. &lt;br /&gt;
MotoMamaMotor leftMotor;&lt;br /&gt;
MotoMamaMotor rightMotor;&lt;br /&gt;
&lt;br /&gt;
void setup(){  // this is our „main“ setup Function&lt;br /&gt;
leftMotor.setup(3,4,5);  // assign the pin numbers for each motor in the setup Function: setup(int newForwardPin, int newReversePin, int newThrottlePin)&lt;br /&gt;
rightMotor.setup(6,7,8);&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
void loop(){  // this is our „main“ loop Function where concrete actions are executed. For example:&lt;br /&gt;
// Start backwards, slow down and accelerate forwards &lt;br /&gt;
for (int i =-255, i&amp;lt;=255;i++){&lt;br /&gt;
leftMotor.setThrottle(i);&lt;br /&gt;
rightMotor.setThrottle(i);&lt;br /&gt;
};&lt;br /&gt;
// Start forwards, slow down and accelerate backwards&lt;br /&gt;
for (int i =255, i&amp;gt;=-255;i--){&lt;br /&gt;
leftMotor.setThrottle(i);&lt;br /&gt;
rightMotor.setThrottle(i);&lt;br /&gt;
};&lt;br /&gt;
};&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Organizing classes in separate files==&lt;br /&gt;
&lt;br /&gt;
We can improve our program structure by putting classes in separate files.&lt;br /&gt;
&lt;br /&gt;
1)&lt;br /&gt;
Click on the arrow in the right corner in order to add a new file.&lt;br /&gt;
Select „new Tab“.&lt;br /&gt;
&lt;br /&gt;
----BILD----&lt;br /&gt;
&lt;br /&gt;
2) &lt;br /&gt;
Enter a filename at the bottom of the window. &lt;br /&gt;
It must end with .h !&lt;br /&gt;
In our case I suggest the name motorControl.h.&lt;br /&gt;
&lt;br /&gt;
3) &lt;br /&gt;
Enter the first line:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
#include „Arduino.h“&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This line „links“ the file to the Arduino-specific features.&lt;br /&gt;
Now we can include the code of our class.&lt;br /&gt;
&lt;br /&gt;
4)&lt;br /&gt;
Go back to your main file.&lt;br /&gt;
Now you have to „link“ the new file to your main file in order to use the features of our class.&lt;br /&gt;
Include the following line in the top of your main file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
#include „MotorControl.h“&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
and write the rest of your program as usual.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==More details on the concept==&lt;br /&gt;
&lt;br /&gt;
Classes can build up on each other (inheritance)&lt;br /&gt;
&lt;br /&gt;
In the beginning we promised that it is possible to replace different motor drivers without changing the rest of the program.&lt;br /&gt;
Classes can indeed include other Objects in the form of „member variables“.&lt;br /&gt;
&lt;br /&gt;
C++ allows class declarations and the code for included Functions to be be placed in different files. &lt;br /&gt;
If you want to know more about that you can read this article about creating libraries in Arduino: [http://arduino.cc/en/Hacking/LibraryTutorial http://arduino.cc/en/Hacking/LibraryTutorial ]&lt;/div&gt;</summary>
		<author><name>Veja6203</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=File:OOPARD2.jpg&amp;diff=90116</id>
		<title>File:OOPARD2.jpg</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=File:OOPARD2.jpg&amp;diff=90116"/>
		<updated>2017-03-28T11:12:45Z</updated>

		<summary type="html">&lt;p&gt;Veja6203: Veja6203 uploaded a new version of File:OOPARD2.jpg&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;File uploaded with MsUpload&lt;/div&gt;</summary>
		<author><name>Veja6203</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90115</id>
		<title>GMU:Functions and Classes (Arduino)</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=GMU:Functions_and_Classes_(Arduino)&amp;diff=90115"/>
		<updated>2017-03-28T11:09:05Z</updated>

		<summary type="html">&lt;p&gt;Veja6203: /* Example: Controlling Motors */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Motivation==&lt;br /&gt;
&lt;br /&gt;
Soon after starting to write the program for your robot you will encounter some typical problems:&lt;br /&gt;
&lt;br /&gt;
* clarity: the bigger the program gets the harder it is to keep the general overview&lt;br /&gt;
* decoupling: you only want to change a certain part of the program without influencing all the rest&lt;br /&gt;
* recyclability: there are several similar parts in your robot for which you would like to reuse particular sections of your code&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
These problems reach back to the beginning of programming and their solution is an art and a science at the same time.&lt;br /&gt;
It generally helps a lot to separate your program into single subunits that are relatively independent from each other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example: Controlling Motors==&lt;br /&gt;
&lt;br /&gt;
The [http://arduino.cc/de/Reference/FunctionDeclaration function] is an enormous useful tool that can help you structuring your code. Functions allow you to sum up several operations under the same command. This command can be called again and again without knowing about or duplicating the included code. &lt;br /&gt;
&lt;br /&gt;
Here is an example for a function for setting the speed of a motor that is connected to an H-bridge:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD1.jpg]]&lt;br /&gt;
&lt;br /&gt;
[[File:OOPARD2.jpg]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now (and for every prospective motor movement) we only need to write one single line in order to for instance setting the left wheels speed:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;setMotorSpeed(speed, leftForwardPin, leftReversePin, leftThrottlePin); // the pin numbers are saved in variables&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This already saves us a lot of typing –&lt;br /&gt;
But one thing still seems quite laborious: we have to know the exact pin numbers every time we want to change the speed.&lt;br /&gt;
&lt;br /&gt;
Imagine a program in which similar function calls are distributed all over. &lt;br /&gt;
In case of a hardware update you would have to find every single function call and change the parameters manually. &lt;br /&gt;
This effort could surely be spent for more useful things..&lt;br /&gt;
&lt;br /&gt;
It would be ideal to find a way of calling a certain function that only offers the most useful parameters (like setting the speed) and which handles technical details (switching pins on and off) internally.&lt;br /&gt;
&lt;br /&gt;
==Possible solution: Data and code in one package „Classes“ and „Objects“==&lt;br /&gt;
&lt;br /&gt;
C++ (and also Arduino) provides a specific feature that can solve our problem: Classes and Objects&lt;br /&gt;
&lt;br /&gt;
A Class predefines common qualities of a group of Objects. &lt;br /&gt;
It for instance determines that every motor has the possibility to exert a certain amount of throttle. &lt;br /&gt;
The corresponding program could look like this:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;class Motor{&lt;br /&gt;
public: // the following qualities and methods are visible from the outside.&lt;br /&gt;
void setThrottle(int newThrottle); // every motor has the possibility to exert trottle.&lt;br /&gt;
}&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now the computer knows that there is a class called „Motor“.&lt;br /&gt;
This class (class) provides a function called „setThrottle“ that is called as an argument by using a number (int) and that does not return anything (void).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Classes are Data-types===&lt;br /&gt;
&lt;br /&gt;
We can use our „Motor“ - class the same way we are using other data - types (int, long, float).&lt;br /&gt;
The following lines use that quality in order to implement two motors:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Motor leftMotor; //  declare an object of the type „Motor“ called „leftMotor“ &lt;br /&gt;
Motor rightMotor; //  declare another object of the type „Motor“ called „rightMotor“ &lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Calling inner functions of a class (Methods)===&lt;br /&gt;
&lt;br /&gt;
Imagine we want to drive the left motor with full throttle whereas the right motor should stop completely. &lt;br /&gt;
This can be expressed as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;// the objetcs name „leftMotor“ and the herein implemented function „setThrottle“ are separated by a dot.&lt;br /&gt;
leftMotor.setThrottle(255);&lt;br /&gt;
rightMotor.setThrottle(0);&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A positive side effect: your program gains readability by picking distinct names for your Objects and Methods.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Classes can contain other variables that can only be accessed „internally“===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do the Objects „leftMotor“ and „rightMotor“ know which pins they want to switch on and off?&lt;br /&gt;
&lt;br /&gt;
Until now our „Motor“ class is quite abstract since it does not contain this information. &lt;br /&gt;
A class that should conduct practical actions needs further variables (concrete pin numbers) and lines of code that describe what to do exactly.&lt;br /&gt;
We can simply include both things in the class definition:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
class MotoMamaMotor {&lt;br /&gt;
...&lt;br /&gt;
private: // the following definitions are only of „internal use“ for the class itself       &lt;br /&gt;
int forwardPin; //  c &lt;br /&gt;
int reversePin;&lt;br /&gt;
int throttlePin;&lt;br /&gt;
...&lt;br /&gt;
};&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do we include the pin numbers into the Object if they are not visible from the outside?&lt;br /&gt;
We simply write a „setup“ Function for the class:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
class MotoMamaMotor {&lt;br /&gt;
private:&lt;br /&gt;
...&lt;br /&gt;
public: //  we want the setup-function to be accessible from the outside.&lt;br /&gt;
void setup (int newForwardPin, int newReversePin, int newThrottlePin){&lt;br /&gt;
// we remember the pins for future use          &lt;br /&gt;
forwardPin=newForwardPin;&lt;br /&gt;
reversePin=newReversePin;&lt;br /&gt;
throttlePin=newThrottlePin;&lt;br /&gt;
// and at the same time we initialize the outputs ! &lt;br /&gt;
digitalWrite(throttlePin,LOW); //  so that the motors don’t spin directly from the beginning .. &lt;br /&gt;
pinMode(forwardPin,OUTPUT);&lt;br /&gt;
pinMode(reversePin,OUTPUT);&lt;br /&gt;
pinMode(throttlePin,OUTPUT);&lt;br /&gt;
}&lt;br /&gt;
...&lt;br /&gt;
};&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==A complete example ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to construct a complete example we only have to include the „speed“-Function (see description above):&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
// Defining a class for motor control &lt;br /&gt;
&lt;br /&gt;
class MotoMamaMotor {&lt;br /&gt;
&lt;br /&gt;
private: // the following definitions are only of „internal use“ for the class itself&lt;br /&gt;
int forwardPin; //Every MotoMamaMotor type Object has its own forwardPin&lt;br /&gt;
int reversePin;&lt;br /&gt;
int throttlePin;&lt;br /&gt;
&lt;br /&gt;
public: // the following qualities and methods are visible from the outside.&lt;br /&gt;
//  This setup-Function has to be called before using the motor control&lt;br /&gt;
void setup(int newForwardPin, int newReversePin, int newThrottlePin){&lt;br /&gt;
// we remember the pins for future use          &lt;br /&gt;
forwardPin=newForwardPin;&lt;br /&gt;
reversePin=newReversePin;&lt;br /&gt;
throttlePin=newThrottlePin;&lt;br /&gt;
// and at the same time we initialize the outputs ! &lt;br /&gt;
digitalWrite(throttlePin,LOW); //  so that the motors don’t spin directly from the beginning .. &lt;br /&gt;
pinMode(forwardPin,OUTPUT);&lt;br /&gt;
pinMode(reversePin,OUTPUT);&lt;br /&gt;
pinMode(throttlePin,OUTPUT);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// this Function allows to control the motor speed &lt;br /&gt;
void setThrottle (int newThrottle){&lt;br /&gt;
if (newThrottle&amp;gt;0){ // should it spin forwards or backwards?&lt;br /&gt;
// spin forwards&lt;br /&gt;
digitalWrite(reversePin,LOW);&lt;br /&gt;
digitalWrite(forwardPin,HIGH);&lt;br /&gt;
}else{&lt;br /&gt;
// spin backwards&lt;br /&gt;
digitalWrite(forwardPin,LOW);&lt;br /&gt;
digitalWrite(reversePin,HIGH);&lt;br /&gt;
}&lt;br /&gt;
// adjust the speed:&lt;br /&gt;
analogWrite(throttlePin, newThrottle);&lt;br /&gt;
}&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
// create two separate MotoMamaMotor type Objects (leftMotor, rightMotor). They can be used as normal variables. &lt;br /&gt;
MotoMamaMotor leftMotor;&lt;br /&gt;
MotoMamaMotor rightMotor;&lt;br /&gt;
&lt;br /&gt;
void setup(){  // this is our „main“ setup Function&lt;br /&gt;
leftMotor.setup(3,4,5);  // assign the pin numbers for each motor in the setup Function: setup(int newForwardPin, int newReversePin, int newThrottlePin)&lt;br /&gt;
rightMotor.setup(6,7,8);&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
void loop(){  // this is our „main“ loop Function where concrete actions are executed. For example:&lt;br /&gt;
// Start backwards, slow down and accelerate forwards &lt;br /&gt;
for (int i =-255, i&amp;lt;=255;i++){&lt;br /&gt;
leftMotor.setThrottle(i);&lt;br /&gt;
rightMotor.setThrottle(i);&lt;br /&gt;
};&lt;br /&gt;
// Start forwards, slow down and accelerate backwards&lt;br /&gt;
for (int i =255, i&amp;gt;=-255;i--){&lt;br /&gt;
leftMotor.setThrottle(i);&lt;br /&gt;
rightMotor.setThrottle(i);&lt;br /&gt;
};&lt;br /&gt;
};&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Organizing classes in separate files==&lt;br /&gt;
&lt;br /&gt;
We can improve our program structure by putting classes in separate files.&lt;br /&gt;
&lt;br /&gt;
1)&lt;br /&gt;
Click on the arrow in the right corner in order to add a new file.&lt;br /&gt;
Select „new Tab“.&lt;br /&gt;
&lt;br /&gt;
----BILD----&lt;br /&gt;
&lt;br /&gt;
2) &lt;br /&gt;
Enter a filename at the bottom of the window. &lt;br /&gt;
It must end with .h !&lt;br /&gt;
In our case I suggest the name motorControl.h.&lt;br /&gt;
&lt;br /&gt;
3) &lt;br /&gt;
Enter the first line:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
#include „Arduino.h“&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This line „links“ the file to the Arduino-specific features.&lt;br /&gt;
Now we can include the code of our class.&lt;br /&gt;
&lt;br /&gt;
4)&lt;br /&gt;
Go back to your main file.&lt;br /&gt;
Now you have to „link“ the new file to your main file in order to use the features of our class.&lt;br /&gt;
Include the following line in the top of your main file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
#include „MotorControl.h“&lt;br /&gt;
&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
and write the rest of your program as usual.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==More details on the concept==&lt;br /&gt;
&lt;br /&gt;
Classes can build up on each other (inheritance)&lt;br /&gt;
&lt;br /&gt;
In the beginning we promised that it is possible to replace different motor drivers without changing the rest of the program.&lt;br /&gt;
Classes can indeed include other Objects in the form of „member variables“.&lt;br /&gt;
&lt;br /&gt;
C++ allows class declarations and the code for included Functions to be be placed in different files. &lt;br /&gt;
If you want to know more about that you can read this article about creating libraries in Arduino: [http://arduino.cc/en/Hacking/LibraryTutorial http://arduino.cc/en/Hacking/LibraryTutorial ]&lt;/div&gt;</summary>
		<author><name>Veja6203</name></author>
	</entry>
	<entry>
		<id>https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=File:OOPARD2.jpg&amp;diff=90114</id>
		<title>File:OOPARD2.jpg</title>
		<link rel="alternate" type="text/html" href="https://www.uni-weimar.de/kunst-und-gestaltung/wiki/index.php?title=File:OOPARD2.jpg&amp;diff=90114"/>
		<updated>2017-03-28T11:09:03Z</updated>

		<summary type="html">&lt;p&gt;Veja6203: File uploaded with MsUpload&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;File uploaded with MsUpload&lt;/div&gt;</summary>
		<author><name>Veja6203</name></author>
	</entry>
</feed>