Advertisement
skizziks_53

Arduino Mission Impossible

Apr 27th, 2018
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.82 KB | None | 0 0
  1. /*
  2.    April 27, 2018
  3.    This sketch doesn't work.
  4.    It is an example of an attempt to allow one class to access the public properties of another different class.
  5. */
  6.  
  7. #include "Arduino.h"
  8.  
  9. //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  10. class Thing1
  11. {
  12.   public:
  13.     Thing1();
  14.     int Value1;
  15.     float Value2;
  16.     long Value3;
  17. };
  18.  
  19. Thing1::Thing1() {
  20.   Value1 = 0;
  21.   Value2 = 0;
  22.   Value3 = 0;
  23. }
  24. //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  25. class Thing2
  26. {
  27.   public:
  28.     Thing2();
  29.     void Change_Thing1_Value1(int);
  30.     void Change_Thing1_Value2(float);
  31.     void Change_Thing1_Value3(long);
  32. };
  33.  
  34. Thing2::Thing2() {
  35.   // nuthin
  36. }
  37.  
  38. void Thing2::Change_Thing1_Value1(int cValue)
  39. {
  40.   Thing1.Value1 = cValue; // This is what should happen here.
  41. }
  42.  
  43. void Thing2::Change_Thing1_Value2(float cValue)
  44. {
  45.   Thing1.Value2 = cValue; // This is what should happen here.
  46. }
  47.  
  48. void Thing2::Change_Thing1_Value3(long cValue)
  49. {
  50.   Thing1.Value3 = cValue; // This is what should happen here.
  51. }
  52.  
  53. //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  54.  
  55. Thing1 example1 = Thing1();
  56. Thing2 example2 = Thing2();
  57.  
  58. void setup() {
  59.   Serial.begin(9600);
  60.   example1.Value1 = 3; // Set initial values here.
  61.   example2.Value2 = 4.3;
  62.   example2.Value3 = 8;
  63. }
  64.  
  65. void loop() {
  66.  
  67.   // Print the initial values
  68.   Serial.println("Point #1");
  69.   Serial.println(example1.Value1);
  70.   Serial.println(example1.Value2);
  71.   Serial.println(example1.Value3);
  72.   Serial.println(" ");
  73.  
  74.   // Change the initial values
  75.   example2.Change_Thing1_Value1(4);
  76.   example2.Change_Thing1_Value2(5.1);
  77.   example2.Change_Thing1_Value3(11);
  78.  
  79.   // Print the new values
  80.   Serial.println("Point #2");
  81.   Serial.println(example1.Value1);
  82.   Serial.println(example1.Value2);
  83.   Serial.println(example1.Value3);
  84.   Serial.println(" ");
  85.  
  86.   Serial.println("Finished");
  87.  
  88.   delay(10000);
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement