Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- April 27, 2018
- This sketch doesn't work.
- It is an example of an attempt to allow one class to access the public properties of another different class.
- */
- #include "Arduino.h"
- //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
- class Thing1
- {
- public:
- Thing1();
- int Value1;
- float Value2;
- long Value3;
- };
- Thing1::Thing1() {
- Value1 = 0;
- Value2 = 0;
- Value3 = 0;
- }
- //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
- class Thing2
- {
- public:
- Thing2();
- void Change_Thing1_Value1(int);
- void Change_Thing1_Value2(float);
- void Change_Thing1_Value3(long);
- };
- Thing2::Thing2() {
- // nuthin
- }
- void Thing2::Change_Thing1_Value1(int cValue)
- {
- Thing1.Value1 = cValue; // This is what should happen here.
- }
- void Thing2::Change_Thing1_Value2(float cValue)
- {
- Thing1.Value2 = cValue; // This is what should happen here.
- }
- void Thing2::Change_Thing1_Value3(long cValue)
- {
- Thing1.Value3 = cValue; // This is what should happen here.
- }
- //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
- Thing1 example1 = Thing1();
- Thing2 example2 = Thing2();
- void setup() {
- Serial.begin(9600);
- example1.Value1 = 3; // Set initial values here.
- example2.Value2 = 4.3;
- example2.Value3 = 8;
- }
- void loop() {
- // Print the initial values
- Serial.println("Point #1");
- Serial.println(example1.Value1);
- Serial.println(example1.Value2);
- Serial.println(example1.Value3);
- Serial.println(" ");
- // Change the initial values
- example2.Change_Thing1_Value1(4);
- example2.Change_Thing1_Value2(5.1);
- example2.Change_Thing1_Value3(11);
- // Print the new values
- Serial.println("Point #2");
- Serial.println(example1.Value1);
- Serial.println(example1.Value2);
- Serial.println(example1.Value3);
- Serial.println(" ");
- Serial.println("Finished");
- delay(10000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement